通過設(shè)置textField的attributedPlaceholder屬性來(lái)設(shè)置占位文字的樣式
// 文字屬性
NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
attrs[NSForegroundColorAttributeName] = [UIColor grayColor];
// NSAttributedString : 帶有屬性的文字(富文本技術(shù))
NSAttributedString *placeholder = [[NSAttributedString alloc] initWithString:@"手機(jī)號(hào)" attributes:attrs];
self.phoneField.attributedPlaceholder = placeholder;
設(shè)置當(dāng)前控制器狀態(tài)欄的樣式侨拦。
/**
* 讓當(dāng)前控制器對(duì)應(yīng)的狀態(tài)欄是白色
*/
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
設(shè)置TextField引出的鍵盤的輔助控件
// 設(shè)置工具條
self.nameField.inputAccessoryView = toolbar;
/**添加UITextView監(jiān)聽事件**/
-(void)registerTextField
{
[self.QQNumber addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
[self.callNumber addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
[self.realName addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
}
//當(dāng)textField的內(nèi)容發(fā)生改變時(shí)調(diào)用
-(void)textFieldDidChange:(UITextField*)textField
{
}
/**UITextViewDelegate的方法解析**/
/**
* 當(dāng)點(diǎn)擊鍵盤右下角的return key時(shí),就會(huì)調(diào)用這個(gè)方法
*/
- (BOOL)textFieldShouldReturn:(UITextField *)textField
/**
* return NO時(shí)酵使,擊所有的textField不可編輯
*/
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
/**
* 當(dāng)點(diǎn)TextField時(shí),就會(huì)調(diào)用這個(gè)方法
*? 鍵盤彈出就會(huì)調(diào)用這個(gè)方法
*/
- (void)textFieldDidBeginEditing:(UITextField *)textField
/**
* return NO時(shí),第一次點(diǎn)擊的TextField可以點(diǎn)擊永部,之后點(diǎn)擊的textField不可編輯
*/
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
監(jiān)聽鍵盤事件通知對(duì)象的生成與移除
// 監(jiān)聽鍵盤的即將顯示事件. UIKeyboardWillShowNotification
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
// 監(jiān)聽鍵盤即將消失的事件. UIKeyboardWillHideNotification
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHidden:) name:UIKeyboardWillHideNotification object:nil];
//移除鍵盤監(jiān)聽
[[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillHideNotification object:nil];
設(shè)置button的標(biāo)題的顏色(只有這種方式的設(shè)置才有效)
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor yellowColor]forState:UIControlStateHighlighted];
獲取當(dāng)前手機(jī)系統(tǒng)的版本
[UIDevice currentDevice].systemVersion.floatValue
在IOS8.0以后的版本UIButton的titleLabel.size = CGSizeMake(0,0)
如果想獲取button.titleLabel.size = CGSizeMake(self.titleLabel.intrinsicContentSize.height顽决,self.titleLabel.intrinsicContentSize.width);
獲取斜體字的UIFont對(duì)象
+ (UIFont *)italicSystemFontOfSize:(CGFloat)fontSize;
設(shè)置UILabel文字水平居中评矩,水平向左剑辫,水平向右
label.textAlignment = NSTextAlignmentLeft;
label.textAlignment = NSTextAlignmentCenter;
label.textAlignment = NSTextAlignmentRight;
如果想注明某個(gè)方法已經(jīng)被廢棄(淘汰),可以如下:
- (void)hide:(BOOL)animated afterDelay:(NSTimeInterval)delay __attribute__((deprecated("Use hideAnimated:afterDelay: instead.")));
/*When you elect to position the view using auto layout by adding your own constraints,
you must set this property to NO.*/
//當(dāng)你選擇通過添加約束的方式來(lái)自定義布局時(shí)流礁,你需要設(shè)置該屬性的值為NO涕俗;
屬性:translatesAutoresizingMaskIntoConstraints
如何使用cocoaPods下載指點(diǎn)版本的三方框架?神帅!
使用UIAlertController時(shí)再姑,對(duì)UIAlertController對(duì)象設(shè)置完畢之后,需要將UIAlertController顯示出來(lái)找御。
一般情況是將它以model的形式推出元镀。
[self presentViewController:alertVC animated:YES completion:nil];
生成圓形圖片的效果有兩種方式
第一種方式其實(shí)很簡(jiǎn)單:
UIImageView* imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"canna"]];
imageView.layer.masksToBounds = YES;
imageView.layer.cornerRadius = imageView.frame.size.width * 0.5;
第二種方式利用圓形路徑對(duì)圖像進(jìn)行裁剪。
// 1.開啟一個(gè)透明的上下文UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0f);
// 2.加入一個(gè)圓形路徑到圖形上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
CGContextAddEllipseInRect(ctx, rect);
// 3裁剪
CGContextClip(ctx);
// 4.繪制圖像
[self drawInRect:rect];
// 5.獲取圖像
UIImage* circleImage = UIGraphicsGetImageFromCurrentImageContext();
// 6.關(guān)閉上下文
UIGraphicsEndImageContext();
使用UIPickerViewController獲取相冊(cè)和相機(jī)時(shí)霎桅,有提示文字的地方是英文.
UIPickerViewController的一些基本操作
1.判斷系統(tǒng)相機(jī)權(quán)限是否可用
[UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]
2.創(chuàng)建UIPickerViewController對(duì)象
_imagePicker = [[UIImagePickerController alloc] init];
//代理
_imagePicker.delegate = self;
//類型
_imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
_imagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
//隱藏系統(tǒng)相機(jī)操作
_imagePicker.showsCameraControls = NO;
3.設(shè)置相機(jī)全屏
CGSize screenBounds = [UIScreen mainScreen].bounds.size;
CGFloat cameraAspectRatio = 4.0f/3.0f;
CGFloat camViewHeight = screenBounds.width * cameraAspectRatio;
CGFloat scale = screenBounds.height / camViewHeight;
_imagePicker.cameraViewTransform = CGAffineTransformMakeTranslation(0, (screenBounds.height - camViewHeight) / 2.0);
_imagePicker.cameraViewTransform = CGAffineTransformScale(_imagePicker.cameraViewTransform, scale, scale);
4.如果更換體統(tǒng)拍照的界面需要給
_imagePicker.cameraOverlayView 屬性賦值栖疑。
實(shí)現(xiàn)動(dòng)態(tài)操作的一些方法
//在多少時(shí)間之后,執(zhí)行某個(gè)操作滔驶。
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//動(dòng)態(tài)的執(zhí)行某個(gè)操作
[UIView animateWithDuration:1 animations:^{
lb.alpha = 0.0;
} completion:^(BOOL finished) {
[lb removeFromSuperview];
}];
});
IOS去掉TableView討厭的系統(tǒng)自帶的分割線
//去掉分割線
//設(shè)置分割的樣式為None遇革。
tableView.separatorStyle = UITableViewCellSelectionStyleNone;
要將其他控制器添加到另一個(gè)控制器里面
//1.創(chuàng)建該控制器
self.sideMenuVC = [[WSDSideMenuViewController alloc]
initWithNibName:@"WSDSideMenuViewController"
bundle:nil];
//2.將該控制器的View添加到當(dāng)前控制器的View上
[self.view addSubview:self.sideMenuVC.view];
//3.將該控制器作為子控制器添加到當(dāng)前控制器的自控制器上。
[self addChildViewController:self.sideMenuVC];
//移除iOS7之后揭糕,cell默認(rèn)左側(cè)的分割線邊距
//實(shí)現(xiàn)tableView代理的方法萝快。
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{? //將要顯示Cell的時(shí)候調(diào)用
cell.separatorInset = UIEdgeInsetsZero;
cell.layoutMargins = UIEdgeInsetsZero;
cell.preservesSuperviewLayoutMargins = NO;
}
//生成二維碼圖片
// 1.實(shí)例化二維碼濾鏡 ,生成二維碼濾鏡對(duì)象著角。
CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
// 2.恢復(fù)濾鏡的默認(rèn)屬性 (因?yàn)闉V鏡有可能保存上一次的屬性)
[filter setDefaults];
// 3.將字符串轉(zhuǎn)換成NSdata
//http://120.25.80.3/getData.ashx?action=ScanQrCodeAddPump&ProjectId=46&pumpId=12
NSData *data? = [@"http://www.reibang.com/users/2a3ae53c85b6/latest_articles" dataUsingEncoding:NSUTF8StringEncoding];
// 4.通過KVO設(shè)置濾鏡, 傳入data, 將來(lái)濾鏡就知道要通過傳入的數(shù)據(jù)生成二維碼
[filter setValue:data forKey:@"inputMessage"];
// 5.生成二維碼
CIImage *outputImage = [filter outputImage];
UIImage *image = [UIImage? imageWithCIImage:outputImage];