【问题标题】:SetTitle for buttons in iPhone SDK > 3.0iPhone SDK > 3.0 中按钮的 SetTitle
【发布时间】:2009-09-21 12:29:33
【问题描述】:

今天我已经安装了 iPhone SDK 3.1 以及相应的 XCode。发生的事情是我所有的按钮都失去了它们的标题。这是我的按钮创建代码:

UIButton *dateButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] initWithFrame:CGRectMake(240.0, 57.0, 60.0, 30.0)];
        [dateButton setTitle:@"Date" forState:UIControlStateNormal];
        [dateButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [dateButton setBackgroundImage:[UIImage imageNamed:@"bg_headline.png"] forState:UIControlStateNormal];
        [dateButton addTarget:self action:@selector(GoToDateSettings:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:dateButton];

任何想法是什么问题?此代码在 中完美运行

问候, 姆拉登

【问题讨论】:

    标签: iphone button


    【解决方案1】:

    复制和粘贴:应该是不言自明的。 SDK 3.x 中的行为发生了变化。干杯,乔丹

            UIButton *dateButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            [dateButton setFrame:CGRectMake(240.0, 57.0, 60.0, 30.0)];
            [dateButton setTitle:@"Date" forState:UIControlStateNormal];
    
            [dateButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [dateButton setBackgroundImage:[UIImage imageNamed:@"bg_headline.png"] forState:UIControlStateNormal];
            [dateButton addTarget:self action:@selector(GoToDateSettings:) forControlEvents:UIControlEventTouchUpInside];
            [self.view addSubview:dateButton];
    

    【讨论】:

      【解决方案2】:
      [dateButton.titleLabel setTitle:@"Date" forState:UIControlStateNormal];
      

      UILabels 和 UITableView 单元格现在在 3.0+ 中更加可定制。我是通过查看 UIButton 的文档直接找到的。

      【讨论】:

      • 无法在 titleLabel 上调用它... [dateButton setTitle:forState]
      猜你喜欢
      • 1970-01-01
      • 2010-11-06
      • 2010-11-02
      • 1970-01-01
      • 2017-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多