您的位置:首页 > 移动开发 > Objective-C

objective-c 把所有类型为UIButton的子控件放在父视图中央 动态创建按钮

2012-09-20 20:53 525 查看
for(UIView *view in [self.backgroundView subviews])
{
//[view removefromsuperview];
if([[[view superclass] description] isEqualToString:@"UIButton"])
{
UIButton * btn=(UIButton*) view;
btn.titleLabel.text=@"dynamic title";
btn.center=btn.superview.center;
}
}

- (IBAction)addButton:(id)sender {
CGRect frame = CGRectMake(90, 200, 200, 60);
UIButton *someAddButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
someAddButton.backgroundColor = [UIColor clearColor];
[someAddButton setTitle:@"动态添加一个按钮!" forState:UIControlStateNormal];
someAddButton.frame = frame;
[someAddButton addTarget:self action:@selector(someButtonClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:someAddButton]; }

-(void) someButtonClicked{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
message:@"您点击了动态按钮!"
delegate:self
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alert show]; }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐