iPhone: Override UIButton buttonWithType to return subclass

后端 未结 3 1194
终归单人心
终归单人心 2021-01-17 17:39

I want to be able to create a UIButton with an oversized responsive area. I know that one way to do that is to override the hitTest method in a subclass, but how do I insta

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-17 18:20

    Here's how I do it:

    + (instancetype)customButtonWithCustomArgument:(id)customValue {
        XYZCustomButtom *customButton = [super buttonWithType:UIButtonTypeSystem];
        customButton.customProperty = customValue;
        [customButton customFunctionality];
        return customButton;
    }
    

    Works also with other types, UIButtonTypeSystem is just an example.

提交回复
热议问题