我是iphone的新手.我发现UILabel
实例方法对我来说很难实现。如何使用它。如何通过子类化UILabel
来进一步自定义UIlabel
文本的外观。拜托,我几乎不需要帮助来启动。敌人的例子,我的viewController
里有一个标签,我怎样才能把它的文本和锄头变成子类.提前谢谢。
您可以使用
UILabel
的许多属性,例如:
UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 100, 40)];
lbl.font = [UIFont fontWithName:@"Helvetica" size:12.0]; // For setting font style with size
lbl.textColor = [UIColor whiteColor]; //For setting text color
lbl.backgroundColor = [UIColor clearColor]; // For setting background color
lbl.textAlignment = UITextAlignmentCenter; // For setting the horizontal text alignment
lbl.numberOfLines = 2; // For setting allowed number of lines in a label
lbl.lineBreakMode = UILineBreakModeWordWrap; // For setting line break mode
lbl.text = @"TitleText"; // For setting the text inside the label
让我知道你想知道的还有什么
!!两种方法
- (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines
{
return CGRectInset(bounds, MARGIN, MARGIN);
}
- (void)drawTextInRect:(CGRect)rect
{
[super drawTextInRect: CGRectInset(self.bounds, MARGIN, MARGIN)];
}
我们使用 CGRectInset 创建一个大于或小于现有矩形 (bounds
) 的矩形。
对于较小的矩形,请使用正值作为MARGIN
对于较大的矩形,请使用正值作为MARGIN
万事如意!!