更改UISwitch上的text
为要更改Text的UISwitch建立IB连接:例如mySwitch,在代码中改变文字:
((UILabel *)[[[[[[self.mySwitch subviews] lastObject] subviews] objectAtIndex:2] subviews] objectAtIndex:0]).text = @"Foo";
((UILabel *)[[[[[[self.mySwitch subviews] lastObject] subviews] objectAtIndex:2] subviews] objectAtIndex:1]).text = @"Ba在写代码时,发现原来3.1.3下经常用的uiview动画结束后调用事件的方法居然不起作用了,摸索了一下,发现ios4下对uivew的animation处理已经有新的方式了,和大家分享一下:
代码功能:在myview向下移出屏幕的动画结束后,触发事件再将myview移除掉。
ios4以前的用法:
[UIView beginAnimations:@"View Remove" context:nil];
UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationFinish:animationID:finished:context:)];
[UIView setAnimationDuration:0.3f];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
myView.center = CGPointMake(myView.center.x, myView.center.y+480.0);
UIView commitAnimations];
- (void)animationFinish:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
if (animationID == @"View Remove") {
[myView removeFromSuperview];
}
}
Xcode的document已经明确说了setAnimationDidStopSelector :”Use of this method is discouraged in iPhone OS 4.0 and later. You should use the block-based animation methods instead.“,看来这种方法是行不通了,反正在我的模拟器上是不行了,以下是ios4中的实现方法:
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveLinear
animations:^{
settingView.center = CGPointMake(myView.center.x, myView.center.y+480.0);
}
completion:^(BOOL finished){
if (finished){
[myView removeFromSuperview];
}
}
];
看起来更加简洁方便了,但逻辑似乎没有原来好理解了。r";
中国足彩网信息请查看IT技术专栏
2025国考·省考课程试听报名