首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
首页标签uibutton

#uibutton

如何以编程方式创建基本的UIButton?

人生的旅途辣鸡前端
- (void)viewDidLoad { [super viewDidLoad]; [self addMyButton]; // Call add button method on view load } - (void)addMyButton{ // Method for creating button, with background image and other properties UIButton *playButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]; playButton.frame = CGRectMake(110.0, 360.0, 100.0, 30.0); [playButton setTitle:@"Play" forState:UIControlStateNormal]; playButton.backgroundColor = [UIColor clearColor]; [playButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal ]; UIImage *buttonImageNormal = [UIImage imageNamed:@"blueButton.png"]; UIImage *strechableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0]; [playButton setBackgroundImage:strechableButtonImageNormal forState:UIControlStateNormal]; UIImage *buttonImagePressed = [UIImage imageNamed:@"whiteButton.png"]; UIImage *strechableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0]; [playButton setBackgroundImage:strechableButtonImagePressed forState:UIControlStateHighlighted]; [playButton addTarget:self action:@selector(playAction:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:playButton]; }... 展开详请
领券