I have a round button, but i will make it have a backgroud with image.
but when i do it, by setting the (what) property to an image, the button开发者_JAVA百科 becomes rectangle because the image is a rectangle. How do I keep the button round?
Simply by doing this
#import <QuartzCore/QuartzCore.h>
myButton.layer.cornerRadius = 8;
Tested Code:
.h
    -(void)vijayWithApple; 
.m
   -(void)vijayWithApple{
            NSLog(@"vijayWithApple Called");
   }
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"Micky.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(vijayWithApple) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(135.0, 180.0, 40.0, 40.0);//width and height should be same value
button.clipsToBounds = YES;
button.layer.cornerRadius = 20;//half of the width
button.layer.borderColor=[UIColor redColor].CGColor;
button.layer.borderWidth=2.0f;
[self.view addSubview:button];
Restut

Best solution I have found especially for UITableCell. I put the code in awakeFromNib and worked right off the bat.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论