set cornerRadius and setbackgroundimage to UIButton

后端 未结 7 1107

I am trying to set cornerRadius of UIButton but I dont know how to do it.

If I do like this:

button.layer.cornerRadius = 5;

works w

7条回答
  •  滥情空心
    2020-12-23 20:15

    //create button like this

         UIButton *cancel=[[UIButton alloc]initWithFrame:CGRectMake(9, 9,35,35)];
        cancel.backgroundColor=[UIColor  colorWithPatternImage:[UIImage imageNamed:@"BackX.png"]];
    [cancel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
        [cancel.layer setBorderColor: [[UIColor blackColor] CGColor]];
        [cancel.layer setBorderWidth: 1.0];
        cancel.contentMode=UIViewContentModeScaleAspectFill;
        cancel.clipsToBounds=YES;
        cancel.layer.cornerRadius=8.0;
        [cancel addTarget:self action:@selector(cancelbtnclk1:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:cancel];
    

    Before that add QuartzCore Framework and import QuartzCore/CoreAnimation.h in your .h file.

    hope it will helps you..

提交回复
热议问题