标签边框未显示(iOS)

时间:2013-04-08 10:45:09

标签: ios objective-c uilabel border

我在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

Storyboard

2 个答案:

答案 0 :(得分:1)

我尝试使用相同的代码,对我来说它的工作正常。我想你可能会忘记

enter image description here

1.declare with IBOutlet and

2.使用xib标签连接。

再次检查

答案 1 :(得分:1)

#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 框架