我已经在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
框架
关于ios - 标签边框未出现(iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15877144/