android上面的alertview十分簡單(custom的部份)
iOS呢?是否一樣簡單?
[ iOS 7 + Xcode 6.3.1 ]
第一次看別人的code:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"輸入IP" message:@" " delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"確認",nil];
UITextField * txt = [[UITextField alloc] init];
txt.backgroundColor = [UIColor whiteColor];
txt.frame = CGRectMake(alert.center.x+65,alert.center.y+48, 150,23);
[alert addSubview:txt];
[alert show];
結果有跳出警告視窗,但是沒有可以輸入的阿!
於是就繼續查,才發現要加上
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
正確版本:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"輸入IP" message:@" " delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"確認",nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField * txt = [[UITextField alloc] init];
txt.backgroundColor = [UIColor whiteColor];
txt.frame = CGRectMake(alert.center.x+65,alert.center.y+48, 150,23);
[alert addSubview:txt];
[alert show];
當然style也有password/default(無法顯示)/login..之類的,大家可以自行嘗試喔!
end
沒有留言:
張貼留言