繁体   English   中英

标签边框未显示(iOS)

[英]Label border not appearing (iOS)

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

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

在此输入图像描述

1.Eclare与IBOutlet

2.使用xib标签连接。

再次检查

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM