mrugen munshi
mrugen munshi

Reputation: 3607

image setting on uibutton in right side bottom

I am having button of frame (0,0,120,100) and i want to add a image at right side of button .i want to add the image of size (10,10) which i want on right hand side in bottom of the button .

How to do this .I googled but could net get about it.

Upvotes: 0

Views: 4391

Answers (2)

mrugen munshi
mrugen munshi

Reputation: 3607

My answer is suppose say i have uibutton roundedButtonType the code is as follows

        roundedButtonType = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
    [roundedButtonType setImageEdgeInsets:UIEdgeInsetsMake(-10.00, 5.00, -5.00, 0.00)];

By doing this i cant get set image on button whereever i want on the button .

By setting the background image of button earlier the image was getting streched . So i used the above code to get the click event for larger area (on button )which solved my problem.

Upvotes: 6

KingofBliss
KingofBliss

Reputation: 15115

Code as follows,

UIButton *imageBut=[[UIButton alloc]initWithFrame:CGRectMake(x, y, 120, 100)];
UIImageView *img=[[UIImageView alloc] initWithFrame:CGRectMake(110, 90, 10, 10)];
img.userInteractionEnabled=NO;
[imageBut addSubview:img];
[self.view addSubview:imageBut];

x,y is the position of the button in your view.

Upvotes: 3

Related Questions