UIAlertView和UIActivityIndicatorView的使用

UIAlertView用來顯示一個對話框,能夠設置對話框的標題、文案、按鈕的個數和文案,也能夠經過實現delegate來監聽按鈕的的點擊操做。blog

使用UIAlertView時須要注意:字符串

self.alertView = [[UIAlertView alloc] 
initWithTitle:@"警告" 
message:@"警告你,做爲男人必須負責,必須努力!" 
delegate:self 
cancelButtonTitle:@"取消" 
//注意:otherButtonTitles能夠接收多個字符串做爲參數(直到遇到nil終止) otherButtonTitles:@"我是男人",@"我是女人",@"我是小孩", nil];

UIActivityIndicatorView就是你們耳熟能詳的「轉菊花」,使用該控件時須要注意:it

1.該控件的高度和寬度沒法改變(不一樣樣式的菊花大小也不同);class

2.調用addSubView以後該控件也是不可見的,除非調用startAnimatingim

 

- (void) btnClicked : (UIButton*) btn {
    int tag = (int)btn.tag;
    if (tag == 101) {
        self.alertView = [[UIAlertView alloc] initWithTitle:@"警告" message:@"警告你,做爲男人必須負責,必須努力!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"我是男人",@"我是女人",@"我是小孩", nil];
 
        [self.alertView show];
    } else if (tag == 102) {
        self.indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
        self.indicatorView.frame = CGRectMake(100, 100, 80, 80);
        [self.view addSubview:self.indicatorView];
        
        [self.indicatorView startAnimating];
    }
}
相關文章
相關標籤/搜索