开发者

how to implement button with backgroundimage programmatically in iphone

I'm developing images in view with button programmatically in iphone. now I want to add button backgroundimage开发者_StackOverflow for next and previous buttons. I want to add a images for these buttons programmatically.

how to add button image in iphone.


// Add the button like this

UIImage *redButtonImage = [UIImage imageNamed:@"ExitButton.png"];

        UIButton *redButton = [UIButton buttonWithType:UIButtonTypeCustom];
        redButton.frame = CGRectMake(280.0, 10.0, 29.0, 29.0);
        [redButton setBackgroundImage:redButtonImage forState:UIControlStateNormal];

        [view addSubview:redButton];


you can try this

 UIImage *buttonImage = [UIImage imageNamed:@"image.png"];

//create the button and assign the image
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:buttonImage forState:UIControlStateNormal];


//create a UIBarButtonItem with the button as a custom view
//UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];

[button addTarget:self action:@selector(clickActionItem:) forControlEvents:UIControlEventTouchUpInside];

good luck


use this for setting image in you button

[yourButton setBackgroundImage:yourImage forState:UIControlStateNormal];


Try this,

UIButton *yourButton = [UIButton buttonWithType:UIButtonTypeCustom];
yourButton.frame = CGRectMake(0, 0, 80, 40);
[yourButton setBackgroundImage:[UIImage imageNamed:@"backgroungImage.png"] forState:UIControlStateNormal];
[self.view yourButton];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜