开发者

iOS - UIView border-bottom-width?

I know 开发者_Go百科how to set the border & border-width for a UIView.

#import <QuartzCore/QuartzCore.h>
...
view.layer.borderColor = [UIColor redColor].CGColor;
view.layer.borderWidth = 3.0f;

How do I specify to set the exact same property only for border-bottom? like in CSS we have border-bottom-width etc...


You can draw it yourself in drawRect: of the UIView:

- (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));
}


I have checked the Class Reference of the UIView and its layer, but could not find any way to do this with the means given by the os. You could make a 1(or 2/3 whatever you want) pixel high view that sticks to the bottom of the main view.


I could be wrong, but I don't think that is possible with CoreGraphics. To achieve a similar effect, you could create a small view right below your view that is the color and width that you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜