我知道如何为 UIView
设置边框和边框宽度。
#import <QuartzCore/QuartzCore.h>
...
view.layer.borderColor = [UIColor redColor].CGColor;
view.layer.borderWidth = 3.0f;
我该如何指定仅针对 border-bottom
设置完全相同的属性?就像在CSS中我们有border-bottom-width
等...
我知道如何为 UIView
设置边框和边框宽度。
#import <QuartzCore/QuartzCore.h>
...
view.layer.borderColor = [UIColor redColor].CGColor;
view.layer.borderWidth = 3.0f;
我该如何指定仅针对 border-bottom
设置完全相同的属性?就像在CSS中我们有border-bottom-width
等...
- (void)drawRect:(CGRect)rect
{
//draw the bottom border
float borderSize = 1.0f;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
CGContextFillRect(context, CGRectMake(0.0f, self.frame.size.height - borderSize, self.frame.size.width, borderSize));
}
我已经查看了UIView和它的层的类参考文档,但是无法找到任何使用操作系统提供的手段来实现这一点的方法。您可以创建一个高度为1(或2/3,无论您想要的)像素的视图,将其粘贴到主视图的底部。
我可能错了,但我认为使用CoreGraphics不可能实现这一点。要实现类似的效果,您可以在视图下方创建一个小视图,该视图具有所需的颜色和宽度。