转载自:http://wangjun.easymorse.com/?p=763
苹果做事就是方便,利用Interface Builder可以方便的进行界面布局,然后相关控件和相关事件相关联,就可以实现一些界面。
好了,不说了,下面是一个实例:
最后的结果是点击不同的按钮,页面背景色变成相应的颜色:
实现起来很简单:
填写相关的代码:
#import<UIKit/UIKit.h>
@interfaceCt_twoViewController : UIViewController {
IBOutletUIButton*leftButton;
IBOutletUIButton*rightButton;
}
@property(retain,nonatomic)UIButton *leftButton;
@property(retain,nonatomic)UIButton *rightButton;
-(IBAction) clickLeftButton:(id)sender;
-(IBAction) clickRightButton:(id)sender;
@end
-(IBAction) clickLeftButton:(id) sender {
self.view.backgroundColor= [UIColorblueColor];
}
-(IBAction) clickRightButton:(id) sender {
self.view.backgroundColor= [UIColorredColor];
}