ios - 标签边框未出现(iOS)

标签 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

最佳答案

#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/

相关文章:

ios - 通过在 Swift 中添加两个标签而不是标题来自定义导航栏

ios - 使用用户定义的运行时属性的 UILabel 的 cornerRadius 不起作用

ios - 如何从 iOS 应用程序在 viber、Facebook Messenger 和 Instagram 上分享文本?

ios - -[GCKCastDeviceProvider stopDiscovery] 必须在主线程上调用

ios - 将 NSArray 元素分配给适当对象的最佳方法是什么?

ios - 带有对象和键的 UIPicker 使用 JSON

ios - map View 中注释的标注操作

ios - constraintWithItem VS constraintsWithVisualFormat 的自动布局问题

objective-c - NSIndexPath 递增值

ios - 如何在 iOS Swift 中实现标签嵌入到 UIImageView 中,如图所示?