如何在iphone中以编程方式实现具有backgroundimage的按钮

use*_*767 22 iphone uibutton ios

我正在iphone中以编程方式在按钮中开发图像.现在我想为下一个和上一个按钮添加按钮backgroundimage.我想以编程方式为这些按钮添加图像.

如何在iPhone中添加按钮图像.

Sud*_*shu 41

//像这样添加按钮

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];
Run Code Online (Sandbox Code Playgroud)


Ksh*_*ire 8

你可以试试这个

 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];
Run Code Online (Sandbox Code Playgroud)

祝好运