iOS-TextView、UIButton加边框,加下划线

来源:互联网 发布:沈阳seo顾问 编辑:程序博客网 时间:2024/04/30 03:12
textview对象.layer.borderColor = UIColor.grayColor.CGColor;

textview对象.layer.borderWidth = 5; //必须设置宽度,否则加不上

textview对象.layer.cornerRadius = 4;//圆角弧度


UIButton *signBtn = [UIButton buttonWithType:UIButtonTypeCustom];
signBtn.frame = CGRectMake(0, 0, 80, 40);
[signBtn.layer setMasksToBounds:YES];
[signBtn.layer setCornerRadius:10.0]; //设置矩形四个圆角半径
[signBtn.layer setBorderWidth:1.0]; //边框宽度
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

CGColorRef colorref = CGColorCreate(colorSpace,(CGFloat[]){ 1, 0, 0, 1 }); 

[signBtn.layer setBorderColor:colorref];//边框颜色

[signBtn setTitle:@"  " forState:UIControlStateNormal];//button title

[signBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];//title color

[signBtn addTarget:self action:@selector(buttonDonwRecover:) forControlEvents:UIControlEventTouchUpInside];//button 点击回调方法

signBtn.backgroundColor = [UIColor whiteColor];




- (void)buttonDonwRecover:(id)sender

{

    UIButton *btn = (UIButton *)sender;

}



//加下划线

 NSMutableAttributedString *str = [[NSMutableAttributedStringalloc] initWithString:self.resgiterButton.titleLabel.text];

   NSRange strRange = {0,[strlength]};

    [str addAttribute:NSUnderlineStyleAttributeNamevalue:[NSNumbernumberWithInteger:NSUnderlineStyleSingle]range:strRange];

    [self.resgiterButtonsetAttributedTitle:str forState:UIControlStateNormal];




0 0
原创粉丝点击