[英]Label border not appearing (iOS)
我在Interface Builder中創建了一個文本標簽( title_label
),我在我的FirstViewController.h
文件中聲明了它,現在我想為它添加一個邊框。 我添加了代碼來執行此操作,但是當我運行應用程序時,邊框根本不會出現。
這是代碼:
#import "FirstViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface FirstViewController ()
@end
@implementation FirstViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
title_label.layer.borderColor = [UIColor greenColor].CGColor;
title_label.layer.borderWidth = 4.0;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
這是FirstViewController.h
的內容:
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController {
IBOutlet UILabel *title_label;
}
@end
#import <QuartzCore/QuartzCore.h>
- (void)viewDidLoad
{
[super viewDidLoad];
UILabel *title_label = [[UILabel alloc]initWithFrame:CGRectMake(20, 30, 150, 40)];
title_label.text = @"Text Which Comes";
title_label.layer.borderColor = [UIColor greenColor].CGColor;
title_label.layer.borderWidth = 4.0;
title_label.layer.cornerRadius = 5.0;
[self.view addSubview:title_label];
}
導入的 QuartzCore
框架
我嘗試使用相同的代碼,對我來說它的工作正常。 我想你可能會忘記
1.Eclare與IBOutlet
和
2.使用xib標簽連接。
再次檢查
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.