IOS细节小记

来源:互联网 发布:python issubclass 编辑:程序博客网 时间:2024/06/05 00:40

1、如何修改UIButton按下后默认的蓝色效果
有两个简单方法:
(1)修改xib属性检查器 Highlight Tint 的值;
(2)通过代码修改:btn.tintColor=[UIColor grayColor];
(3)使用setBackgroundImage:forState: 方法;
(4)重绘;

2、 使用constraint时, animateWithDuration不起作用,或者有闪烁效果;
(1)首先,animateWithDuration不起作用的原因可能如下:
<1> 没有调用layoutIfNeeded;
<2> 调用layoutIfNeeded的对象不正确;
注意: 为了使constraint的变化显示出来,调用layoutIfNeeded的view应该是受影响的view的superview;

(2)举例

// 1.连线需要修改的约束@property (strong, nonatomic) IBOutlet NSLayoutConstraint *arrowLeadingConstra;// 2.控制箭头的位置[self layoutIfNeeded]; // 必须写,否则会有闪动的效果;[UIView animateWithDuration:0.25 animations:^{    if (button.tag == XBStatusDetailTopToolbarButtonTypeRetweeted && self.arrowLeadingConstra.constant == 150) {            self.arrowLeadingConstra.constant -= 100;    }    if (button.tag == XBStatusDetailTopToolbarButtonTypeComment && self.arrowLeadingConstra.constant == 50){            self.arrowLeadingConstra.constant += 100;    }    [self layoutIfNeeded]; // 必须写,否则没有动画效果;}];
0 0
原创粉丝点击