zoukankan      html  css  js  c++  java
  • objectivec 把所有类型为UIButton的子控件放在父视图中央 动态创建按钮

        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(9020020060);  
        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];  

    }   

  • 相关阅读:
    Python统计字符串中出现次数最多的人名
    初探CORBA组件化编程
    shell脚本—基础知识,变量
    Java多线程--线程交替
    Qt中采用多线程实现Socket编程
    Python字符串格式化--formate()的应用
    JAVA中浅复制与深复制
    Python这些问题你会吗?
    PHP控制反转(IOC)和依赖注入(DI
    Go 语言指针
  • 原文地址:https://www.cnblogs.com/zyip/p/2695950.html
Copyright © 2011-2022 走看看