NSString*contentStr = [NSStringstringWithFormat:@" %@",DetailStr];1.移除所有子視圖的系統方法
[webViewloadHTMLString:contentStrbaseURL:nil];NSString*contentStr = [NSStringstringWithFormat:@"
%@
",DetailStr];
[webViewloadHTMLString:contentStrbaseURL:nil];NSString*contentStr = [NSStringstringWithFormat:@"
%@
",DetailStr];
[webViewloadHTMLString:contentStrbaseURL:nil];NSString*contentStr = [NSStringstringWithFormat:@"
%@
",DetailStr];
[webViewloadHTMLString:contentStrbaseURL:nil];
[cell.contentView.subviewsmakeObjectsPerformSelector:@selector(removeFromSuperview)];
4.按鈕單選的一種實現方法?
timeBtn 為全局變量
if(timeBtn==nil)
{
sender.selected=YES;
timeBtn= sender;
}
elseif(timeBtn!=nil&&timeBtn== sender)
{
timeBtn.selected=YES;
}
elseif(timeBtn!= sender &&timeBtn!=nil)
{
timeBtn.selected=NO;
sender.selected=YES;
timeBtn= sender;
}
}
5.label自適應高度
NSDictionary * attributeDic = [NSDictionary dictionaryWithObjectsAndKeys:font_13, NSFontAttributeName, nil];
CGSize size = CGSizeMake(k_Width - 40, 100); // 設置最大寬高
CGSize addressSize = [_context boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:attributeDic context:nil].size;
addressLabel.numberOfLines = 0;
6.導航欄背景顏色
1、info.plist里添加:View controller-based status bar appearance
設置為NO。
2、代碼里添加:[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
3、導航欄文字顏色
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,nil]];
或者
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
?7.textField的placeholderu顏色
1、NSDictionary *TFdic = @{NSForegroundColorAttributeName:[UIColor grayColor], NSFontAttributeName:[UIFont boldSystemFontOfSize:16]};
2、_UserNameTF.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"請輸入手機號/郵箱" attributes:TFdic];。
?8、圖片拉伸?
UIImage stretchableButtonImage = [buttonImagestretchableImageWithLeftCapWidth:12topCapHeight:0];
參數一:距離圖片左邊的像素距離
參數二:距離圖片上邊的像素距離
9、設置label行間距?
UILabel設置行間距等屬性:
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:contentLabel.text];;
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
[paragraphStyle setLineSpacing:5];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, contentLabel.text.length)];
contentLabel.attributedText = attributedString;
10、NSDate 和 NSString互轉
1、字符串轉時間
NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];//實例化一個NSDateFormatter對象
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//設定時間格式,要注意跟下面的dateString匹配,否則日起將無效
NSDate *date =[dateFormat dateFromString:@"2013-3-11 10:00:01"];
2、時間轉字符串
NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];//實例化一個NSDateFormatter對象
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//設定時間格式
NSString *dateString = [dateFormat stringFromDate:[NSDate date]]; //求出當天的時間字符串,當更改時間格式時,時間字符串也能隨之改變
=========
NSUInteger unitFlags = NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSCalendar * calendar = [[NSCalendar alloc] initWithCalendarIdentifier:@"1"];
NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:myCalendar.currentDate];
[calendarHeaderView addSubview:currentMonthLabel];
11、webView亂碼?
12、修改webView字體大小、字體顏色、背景顏色
// 修改網頁字體大小
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
//字體大小
[webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '330%'"];
//字體顏色
[webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextFillColor= 'gray'"];
//頁面背景色
[webView stringByEvaluatingJavaScriptFromString:@“document.getElementsByTagName('body')[0].style.background='#2E2E2E'"];
}
————— 參考:http://blog.csdn.net/chenyong05314/article/details/40599139
13、將cell里的圖片放大到全屏
bigImgButton.frame= [UIScreenmainScreen].bounds;
AppDelegate*delegate = (AppDelegate*)[UIApplicationsharedApplication].delegate;
[delegate.windowaddSubview:bigImgButton];
14、縮放圖片
//放大縮小圖片
- (void)pinchGestureAction:(UIPinchGestureRecognizer*)pinchGesture
{
if(pinchGesture.state==UIGestureRecognizerStateEnded) {
currentScale= pinchGesture.scale;
}elseif(pinchGesture.state==UIGestureRecognizerStateBegan&¤tScale!=0) {
pinchGesture.scale=currentScale;
}
//設置圖片尺寸縮放界限
CGFloatminScale =0.5;
CGFloatmaxScale =2.5;
if(pinchGesture.scale<= minScale) {
pinchGesture.scale= minScale;
}
if(pinchGesture.scale>= maxScale) {
pinchGesture.scale= maxScale;
}
if(pinchGesture.scale!=NAN) {
pinchGesture.view.transform=CGAffineTransformMakeScale(pinchGesture.scale, pinchGesture.scale);
}
}
14、跳到子視圖 點亮tableBar
15、更改導航欄顏色?
[self.navigationController.navigationBarsetBarTintColor:[UIColorcolorWithRed:27/255.0green:74/255.0blue:70/255.0alpha:1.000]];