iOS笔记

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]];

你可能感兴趣的:(iOS笔记)