UIButton - alloc initWithFrame: vs. buttonWithType:

前端 未结 6 1106
滥情空心
滥情空心 2020-12-06 17:13

Given (arbitrarily):

CGRect frame = CGRectMake(0.0f, 0.0f, 100.0f, 30.0f);

What\'s the difference between the following two code snippets?<

6条回答
  •  一向
    一向 (楼主)
    2020-12-06 17:17

    I would strongly suggest using the first approach (+buttonWithType), because that's the only way to specify the button type.

    If you +alloc and -initWithFrame:, the buttonType is set to some standard value (not sure which, and this could change in later versions of the SDK) and you can't change the type afterwards because the buttonType property is read only.

提交回复
热议问题