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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1.单例的写法 (instancetype)sharedInstance {static id sharedIns...
    sunny_王阅读 3,134评论 0 0
  • iOS8.0之前的定位 前台定位 导入CoreLocation框架和对应的主头文件#import <CoreLoc...
    Developer_Yancy阅读 8,854评论 0 14
  • 地图的基本使用 1.设置地图显示类型// 1.设置地图显示类型 /** MKM...
    Developer_Yancy阅读 10,147评论 3 58
  • 前言 该部分篇章,将会比较碎。主要用于记录自己开发和书籍中看到比较有价值的知识点的记录和归纳。 Objective...
    破晓霜林阅读 3,199评论 0 2
  • 淅淅沥沥的下雨天,心情很低落,看着眼前的“逍遥丸”我不由得苦笑,其实我知道我不该再去想那些被称为“已经过去了”的事...
    葡萄枝子_8112阅读 1,742评论 0 0