ios - UIButton子类: does buttonWithType: return UIButton or subclass instance?

标签 ios objective-c uibutton

如果我子类化 UIButton 并使用其 buttonWithType: 方法创建 button,它是否会返回一个 UIButton code> 还是子类实例?

例如:

@interface MyButton : UIButton
@end

MyButton *button = [MyButton buttonWithType:UIButtonTypeCustom];

或者我必须使用 allocinitWithFrame 来代替?

谢谢

最佳答案

抱歉,我刚刚从 Apple 的文档中找到了此内容:

This method is a convenience constructor for creating button objects with specific configurations. It you subclass UIButton, this method does not return an instance of your subclass. If you want to create an instance of a specific subclass, you must alloc/init the button directly.

关于ios - UIButton子类: does buttonWithType: return UIButton or subclass instance?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15402599/

相关文章:

ios - 防止用户每秒按下按钮 x 次

ios - 优化 - 步进可能表现得很奇怪 : iOS/Unity

objective-c - cocoa touch 问题。在触摸序列上下文中使用 KVO

ios - 如何根据选择的日期显示 UITableView?

objective-c - iOS - 加载自定义表格单元格导致第二次加载出错

ios - CAGradientLayer 没有从 View 中删除自己

ios - 在 segControl & bars 上自定义 UIButton 或 UIBarButtonItem 的背景

iOS 调度异步崩溃

ios - Cocoapods 不生成目标

iphone - 是否可以创建一个UITabBarController,其选项卡项仅具有文本标签(无图标)?