标签边框没有出现(iOS)

问题描述:

我在Interface Builder中创建了一个文本标签(title_label),我已经在我的FirstViewController.h文件中声明了它,现在我想为它添加边框。我已经添加了代码来做到这一点,但是当我运行应用程序时,边框根本不会出现。标签边框没有出现(iOS)

下面是代码:

#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

+0

viewDidLoad中是当每个GUI已加载被调用的方法。你需要做到这一点initWithCoder,因为我假设你正在使用故事板。 – 2013-04-08 10:49:58

+0

你可以检查并符合UILable的IBOutlet吗? – Ganapathy 2013-04-08 10:57:09

+0

只是尝试我的答案,让我知道它是否来临? – 2013-04-08 11:33:23

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

+0

这创建了一个新的标签,而不是我正在寻找的 – user1301428 2013-04-08 11:36:07

+0

我知道,如果这是行得通的,那么问题仅在于您的IBConnections。为了澄清我只是要求你把我的代码....正确检查你的IBConnections – 2013-04-08 11:37:16

+0

我已经检查了我的连接正确,但因为我刚开始,我怎么知道我失踪? :D – user1301428 2013-04-08 11:39:59

我与你相同的代码尝试,对我来说它的工作的罚款。我想你可能会忘记

enter image description here

1.declare与IBOutlet

2.连接用XIB1标签。

检查再次