1

title_label在 Interface Builder 中创建了一个文本标签 ( ),我已经在我的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

故事板

4

2 回答 2

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

于 2013-04-08T11:32:06.370 回答
1

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

在此处输入图像描述

1.用IBOutletand声明

2.用xib标签连接。

再次检查

于 2013-04-08T10:57:22.487 回答