在iphone中设置标签边框
答
您可以通过
Label.layer.borderColor = [UIColor whiteColor].CGColor;
Label.layer.borderWidth = 4.0;
做这个之前,你需要导入一个框架QuartzCore/QuartzCore.h
答
我不确定你可以在默认情况下使用UILabel
。您可能需要考虑使用只读(field.editing = NO)UITextField
并将其设置为borderStyle(可使用UITextBorderStyle
以编程方式完成)。虽然这可能有点“沉重”。另一个选项可能是子类UILabel
绘制您的边框。
或者,根据您的需要,这可能会更好,使用支持CALayer
并使用它的borderColor和borderWidth属性绘制边框。
答
您也可以尝试继承您的标签并重写drawRect:方法绘制或边框或任何你喜欢的:
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
[[UIColor blackColor] setStroke];
CGContextStrokeRect(context, self.bounds);
}
的http://stackoverflow.com/questions/2311591/how-to-draw-border-around-a-uilabel – Vladimir 2010-03-31 10:12:06
可能重复的可能重复[如何在UILabel上绘制边框?](https://stackoverflow.com/questions/2311591/how-to-draw-border-around-a-uilabel) – Suragch 2017-06-10 00:14:45