我使用添加邊框的UIButton下面的代碼,它工作正常,但邊框出現UIButton的area.How外面加上邊框的UIButton area.Please內幫助我..如何在iOS sdk中的UIButton中添加邊框?
[[button1 layer] setBorderWidth:7.0];
[[button1 layer] setBorderColor:[UIColor redColor].CGColor];
我使用添加邊框的UIButton下面的代碼,它工作正常,但邊框出現UIButton的area.How外面加上邊框的UIButton area.Please內幫助我..如何在iOS sdk中的UIButton中添加邊框?
[[button1 layer] setBorderWidth:7.0];
[[button1 layer] setBorderColor:[UIColor redColor].CGColor];
我總是用你的同方法來繪製邊界。 如果你想在裏面畫邊框,你可以使用背景圖片。
[button1 setBackgroundImage:[UIImage imageNamed:@"button1_bckg.png"]
forState:UIControlStateNormal];
沒有直接的方法爲UIView
添加內邊框。但是,您可以爲其添加子視圖。像這樣:(在你的.m文件中實現下面的方法)。
-(void)setInnerBorderFor:(UIView *)aView withFloatVal:(CGFloat)aFloatVal
{
UIView *borderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, aView.frame.size.width, aView.frame.size.height)];
borderView.backgroundColor = [UIColor clearColor];
borderView.layer.borderWidth = aFloatVal;
borderView.layer.borderColor = [UIColor blackColor].CGColor;
[aView addSubview:borderView];
}
然後,您可以撥打:
[self setInnerBorderFor:button1 withFloatVal:7.0f];
別忘了'self.clipsToBounds = YES;'! –
你可以把參考圖像。什麼你想什麼呢? –
你可以去繼承UIButton。 那裏你可以在按鈕上添加另一個子視圖。 然後設置子視圖的框架小於按鈕框架並設置其邊框。 –