我在視圖中使用了一些標籤。我想在我的iPhone應用程序中製作圓角標籤。我使用下面的代碼來做到這一點,但它不工作。我有一些錯誤使用該屬性。如何在iphone中使用圓角標籤,UILabel圓角
label.layer.borderColor = [UIColor blueColor].CGColor;
label.layer.borderWidth = 4.0;
label.layer.cornerRadius = 8;
我在視圖中使用了一些標籤。我想在我的iPhone應用程序中製作圓角標籤。我使用下面的代碼來做到這一點,但它不工作。我有一些錯誤使用該屬性。如何在iphone中使用圓角標籤,UILabel圓角
label.layer.borderColor = [UIColor blueColor].CGColor;
label.layer.borderWidth = 4.0;
label.layer.cornerRadius = 8;
很難確切知道你在問什麼,因爲你沒有包括你得到的錯誤。您是否已將QuartzCore
框架添加到您的項目中並將#import <QuartzCore/CALayer.h>
添加到修改該層的文件中?如果不是這樣,請將錯誤和更多信息添加到您的問題中。
編輯:你也可以#import <QuartzCore/QuartzCore.h>
建議在評論。 QuartzCore.h
包括CALayer.h
以及QuartzCore
組件的其餘部分。
這是正確的答案。 – Rog 2011-12-16 05:32:04
我會創建一個帶圓角的視圖並將標籤添加到該視圖。
就在您的.m文件添加#import <QuartzCore/QuartzCore.h>
,並假設你有一個UILabel *myLabel;
只是做[myLabel.layer setCornerRadius:20];
//值 '20' 可以根據你的願望:)
我改變傳遞相同的問題,在單元格中使用帶有backgroundColor的UILabel,並添加了此功能以正確工作:
label.layer.cornerRadius=8.0;
label.clipsToBounds=YES;
This si mple代碼足夠RoundLabel
LabelName.layer.cornerRadius = LableName.frame.size.height/2;
LabelName.layer.masksToBounds = YES;
如何把一個圓角圖像作爲的UILabel的背景? – Sarah 2011-12-16 05:30:07
可能的重複[如何在iPhone上創建圓角UILabel?](http://stackoverflow.com/questions/510382/how-do-i-create-a-round-cornered-uilabel-on-the -iphone) – Besi 2016-03-31 21:50:35