当前位置: 移动技术网 > IT编程>移动开发>IOS > ios开发swift Button解析

ios开发swift Button解析

2018年04月04日  | 移动技术网IT编程  | 我要评论

南京市长季建业老婆,提灯映桃花,简历封面word

  //创建一个contactAdd类型
    /*
    UIButtonType.system:前面不带图标,默认文字颜色为蓝色,有触摸时的高亮效果
    UIButtonType.custom:定制按钮,前面不带图标,默认文字颜色为白色,无触摸时的高亮效果
     UIButtonType.infoDark:为感叹号“!”圆形按钮
     UIButtonType.contactAdd:前面带“+”图标按钮,默认文字颜色为蓝色,有触摸时的高亮效果
    */

        //按钮状态
        /*
         .normal:普通状态
         .highligted:触摸状态下的文
         .disabled:禁用状态下的文字

         */


        //add类型
        let btn = UIButton(type:.contactAdd);
        btn.frame = CGRect(x:10,y:10,width:100,height:100);
        btn.setTitle("按钮", for: .normal);
        self.view .addSubview(btn);


        //按钮文字阴影
        //btn.setTitleShadowColor(UIColor.red, for: .normal);
    //按钮文字大小
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 11);
        //按钮背景色
        btn.backgroundColor = UIColor.yellow;


        //按钮图标默认单一颜色
       // btn.setImage(UIImage(named:""), for: .normal);

        //保留图标原来颜色
       // let iconImage = UIImage(named:"")?.withRenderingMode(.alwaysOriginal);

       //按钮背景图片
        btn.setBackgroundImage(UIImage(named:""), for: .normal)

        //触摸事件无传递对象
       // btn.addTarget(self, action:#selector(taooed), for:.touchUpInside)
       //有传递对象
       // btn.addTarget(self, action:#selector(taooed(_:)), for: .touchUpInside)

        //btton文字太长时我们自动换行,(按词)
       // btn.titleLabel?.lineBreakMode = .byWordWrapping;
        //按字符
       // btn.titleLabel?.lineBreakMode = .byCharWrapping;
        //当设置了上面这两个中的一个我们可以用(\n)自动换行

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网