繁体   English   中英

如何绘制圆角矩形标签或视图?

[英]How can I draw a rounded rectangle Label or View?

我需要在我的iOS应用程序中绘制一个圆角矩形条,但不使用背景图像。 有没有办法制作圆角矩形视图或标签?

除了其他答案之外,不要忘记设置masksToBounds属性。

#import <QuartzCore/QuartzCore.h>

label.layer.cornerRadius = 5.0;
label.layer.masksToBounds = YES;

如果您正在使用UI设计器(Storyboard或nib文件),则可以选择设置用户定义的运行时属性。

单击要包含圆角的视图,单击“显示标识检查器”(第3个选项卡,右上角)。 然后单击用户定义的运行时属性中的+并输入以下内容:

Key Path: layer.cornerRadius
Type: Number
Value: whatever number, e.g. 5

添加Quartz核心框架..

#import <QuartzCore/QuartzCore.h>

然后设置角半径,

yourView_LabelName.layer.cornerRadius = 10.0;

它可能对你有用。 第1步:将quartzcore框架添加到项目框架中。 要在哪个文件中编写此代码,您必须使用它。

        #import <QuartzCore/QuartzCore.h>
        UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 50, 30)];
        myLabel.text = @"text";
        myLabel.layer.cornerRadius =8.0;
        [self.view addSubview:myLabel];

暂无
暂无

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

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