小编Ste*_*ust的帖子

如何使用标签访问UIButton并更改其图像?

我需要更改UIButtons矩阵上的图像,而我唯一知道的解决按钮的方法是标记.但我找不到一种方法来实际使用这个标识符.在viewDidLoad期间以编程方式创建按钮.

以下是创建按钮的代码:

#define N_ROWS  4
#define N_COLS  3

    int N_IMG = 0;
    for (int a = 0; a < N_COLS; a++) {
        for (int j = 0; j < N_ROWS; j++) {


            UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
            aButton.frame = CGRectMake(a * 65.0 + 25, j * 65.0 + 15, 10.0, 10.0);
            aButton.tag = j + a * N_ROWS + 1;
            [aButton setBackgroundColor:[UIColor redColor]];

            N_IMG = N_IMG++;
            [self.view addSubview:aButton]; 
            number_sorted =  1;

        }
    }
Run Code Online (Sandbox Code Playgroud)

以下是设置图像的代码:

- (IBAction)set_image:(id)sender {

    #define N_ROWS  4 …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uibutton

2
推荐指数
1
解决办法
5242
查看次数

标签 统计

iphone ×1

objective-c ×1

uibutton ×1