ios UI

iso中所有控件都是容器,就是说按钮之中可以放按钮。
控件的frame bounds和center的关系
frame:包含一个矩形,用于指定相对于父视图的坐标和位置大小。
bounds:只有高和宽有效
center:表示控件在父控件中的坐标
addSubView:当前控件添加一个子控件
Superview:返回当前控件的父控件

添加控件
1.在界面里拖个控件
2.@property (nonatomic,retainIBOutlet UILabel *lable;
   (IBOutlet没有具体意义,只是告诉build它写界面控件相关联,不写不行)
3.右键控件->referencing Outlets->new referencing Outlet后的圆圈连接到view里的lable
4.添加事件如下

添加按钮事件
在ViewController里添加完下面方法后,在界面设计器里就会出现该方法用以和按钮连线

// IBAction=void 但事件只识别IBAction
- (IBAction) onClick:(id)sender{
    UIButton *button = (UIButton *)sender;
    UIAlertView *alert = [[UIAlertView alloc] 
                          initWithTitle:@"标题" 
                          message:[button currentTitle] // 按钮文本
                          delegate:self 
                          cancelButtonTitle:@"确定" 
                          otherButtonTitles:@"删除",@"取消",nil]; // 消息框中其它按钮,以nil结尾
    [alert show];
}

为程序添加icon图标
1.将图片拖到.plist文件所在的文件夹里
2.在.plist文件里添加icon file键,设置值为图片名字

显示启动画面
1.将图片拖到.plist文件所在的文件夹里
2.将图片命名为Default.png(gif也行)
3.在(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法里添加[NSThread sleepForTimeInterval:5.0];启动时先睡5秒

 

添加UIAlertView事件
1.给.h文件添加协议<UIAlertViewDelegate>
2.给.h文件声明事件方法- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
3.在.m文件中实现事件方法:
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    NSLog(@"button index is %d", buttonIndex);
}

UIActionSheet应用

UIActionSheet *sheet = [[UIActionSheet alloc]
                                initWithTitle:@"UIActionSheet Title" 
                                delegate:(id<UIActionSheetDelegate>)self 
                                cancelButtonTitle:@"cancel" 
                                destructiveButtonTitle:@"destuctive" 
                                otherButtonTitles:@"other1",@"other2",@"other3", nil];
[sheet showInView:self.view];

事件添加和UIAlertView一样:- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;

UIWebView应用
1.添加UIWebView控件及属性(参照上面添加控件)
2.在viewDidLoad中添加代码:

NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[webView loadRequest:req];

  

posted @ 2013-11-26 21:50  关桐  阅读(192)  评论(0)    收藏  举报