打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
ios问题笔记

ios问题笔记

32位 最多内存0到3G 64位 最多内存0到8GiOS模板code4app.comgithub.comdeveloper.apple.con动画label不能变小 只能变大,(而uiview uiimageview可变大变小,对于uiview uiimageview在动画中指定frame name他就会从当前位置大小过度到你指定的位置和大小)旋转 旋转物体的x= 围绕的物体的 x坐标+cosR角度=(angle/180.0*M_PI)扩充属性如果说今后过程中遇到系统提供的类不能满足需要,那么要立刻想到自定义一个类继承自系统提供的类,在自定义类中扩充在自己想要的属性和方法,但是,要注意在创建对象时用自定义的类创建对象。打点调用字符串指针可以用retain,copy,非字符串指针只能用copy,非指针类型用assign导航条的高度是44终端卸载sudo rm -rf  名字tab键智能获取路径数据持久化fmdb plist  对象序列化 单例类用到全局唯一的对象,就要用单例类,特别是对于某个用户的信息,很可能用到单例类,用户信息是唯一的(单例类);NSFileHandel对文件内容管理NSFileManager是对文件管理目录必须存在地图2大块  Locationframework    (user location and  heading)    Mapkit  (display annotation )   关于发短信 发邮件普遍存在大多数app设置里边 关于修改ARCgar检测是否是arcarc和非arc兼容TARGETS 中DDMenuController.m-fobjc-arc分析项目 大到小 --》小到具体当farm改变 la'youtsuview调用调用layoutsubview的时机一:当view的frame或bounds发生改变1:直接改view的frame或bounds 会调用view中layoutsubview2:当屏幕旋转的时候,视图控制器中根view发生变化,会调用视图控制中viewDidLayoutsuview)二:在当前view上addsubvie添加子view,会调用view中layoutSubview三:改变view的大小的时候,会触发父view的layoutsubview被调用四:当UIScroller中滚动的时候,会调用自身layoutsubview.button select属性数据库》用户》成功》收藏  数据库字符串用长度,数组用个数selector  sel 是哈希 通过哈希算法转化成整数值  在oc中没有找到这个     objicet_SEL 类成员方法的指针可以理解 @selector()就是取类方法的编号,他的行为基本可以等同C语言的中函数指针,只不过C语言中,可以把函数名直接赋给一个函数指针,而Object-C的类不能直接应用函数指针,这样只能做一个@selector语法来取.它的结果是一个SEL类型。这个类型本质是类方法的编号(函数地址)CoreDataZ_PK     是表的主键,从1开始递增,唯一值Z_ENT  表在xcdatamodel 中的索引值,创建了5个表,Z_ENT的区间就是[1,5 ]Z_OPT  表示的是每条数据被操作的次数,初始化值为1,只要是增删改查都会加1iphone开发重要基础知识------委托代理(degegate)?委托代理(degegate),顾名思义,把某个对象要做的事情委托给别的对象去做。那么别的对象就是这个对象的代理,代替它来打理要做的事。反映到程序中, 首先要明确一个对象的委托方是哪个对象,委托所做的内容是什么。委托机制在很多语言中都用到的,这只是个通用的思想,网上会有很多关于这方面的介绍。?  那么在苹果开发过程中,用到委托的程序实现思想如下,我主要拿如何在视图之间传输信息做个例子。譬如:在两个页面(UIIview视 图对象)实现传值,用委托(delegate)可以很好做到。ViewController的生命周期中各方法执行流程如下:init—>loadView—>viewDidLoad—>viewWillApper—>viewDidApper—>viewWillDisapper—>viewDidDisapper—>viewWillUnload->viewDidUnload—>dealloc使用编译器选项来开启和关闭ARC 开发者使用-fobjc-arc 编译选项开启ARC,还可以对某一个文件使用ARC,便于在使用手动引用计数的文件中使用ARC。对于已经使用ARC的工程,仍可以指定一个文件来关闭ARC通过-fno-objc-arc编译选项。编译时候出现路径错误解决办法路径错误需要在search Path的library里改成绝对路径?打包流程1.在MyNslog中修改?2.在TARGETS里的identifier修改3.在build setting里边修改 code singning的release  (project和targets都得修改)注意  钥匙串的添加进去 没有的话需要登录  下载4.然后选为iOS device  在project里边选择  归档在iTunes修改app内容upload需要根据相应账号登录iTunes修改内容 然后再xcode 的tool中  上传cornerStone?ARC 与非ARC 互转1, target -> Build phases -> complie sources     -fobjc-arc    转成arc    -fNo-objc-arc 转成非a缩放效果记住要设置pointCGAffineTransform aff;            aff = CGAffineTransformScale(self.view.transform, 0.5f, 0.5f);            [self.view setTransform:aff];CGAffineTransformRotate(transform, M_PI);是旋转的。?CGAffineTransformMakeRotation(-M_PI);也是旋转的?transform = CGAffineTransformScale(transform, -1.0, 1.0);是缩放的。?view.transform = CGAffineTransformIdentity;线性代数里面讲的矩阵变换,这个是恒等变换???当 你改变过一个view.transform属性或者view.layer.transform的时候需要恢复默认状态的话,记得先把他们重置可以使用view.transform = CGAffineTransformIdentity,或者view.layer.transform = CATransform3DIdentity,Xcode6.0下载地址 http://pan.baidu.com/s/1pJug2xX 密码: e6q2ios动态获取UILabel的高度和宽度分类: UI2012-12-16 15:12 1871人阅读 评论(0) 收藏 举报iosiOSIOSUILabel动态宽度高度在使用UILabel存放字符串时,经常需要获取label的长宽数据,本文列出了部分常用的计算方法。1.获取宽度,获取字符串不折行单行显示时所需要的长度CGSize titleSize = [aString sizeWithFont:font constrainedToSize:CGSizeMake(MAXFLOAT, 30)];注:如果想得到宽度的话,size的width应该设为MAXFLOAT。2.获取高度,获取字符串在指定的size内(宽度超过label的宽度则换行)所需的实际高度.CGSize titleSize = [aString sizeWithFont:font constrainedToSize:CGSizeMake(label.frame.size.width, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];注:如果想得到高度的话,size的height应该设为MAXFLOAT。3.实际编程时,有时需要计算一段文字最后一个字符的位置,并在其后添加图片或其他控件(如info图标),下面代码为计算label中最后一个字符后面一位的位置的方法。CGSize sz = [label.text sizeWithFont:label.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];CGSize linesSz = [label.text sizeWithFont:label.font constrainedToSize:CGSizeMake(label.frame.size.width, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];if(sz.width <= linesSz.width) //判断是否折行{        lastPoint = CGPointMake(label.frame.origin.x + sz.width, label.frame.origin.y);  }else  {          lastPoint = CGPointMake(label.frame.origin.x + (int)sz.width % (int)linesSz.width,linesSz.height - sz.height);  }iOS开发之指定UIView的某几个角为圆角 2013-11-15 10:58:56|  分类: 技术日志|举报|字号 订阅如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可(项目需要使用QuartzCore框架)。而若要指定某几个角(小于4)为圆角而别的不变时,这种方法就不好用了。对于这种情况,Stackoverflow上提供了几种解决方案。其中最简单优雅的方案,就是使用UIBezierPath。下面给出一段示例代码。UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(120, 10, 80, 80)];view2.backgroundColor = [UIColor redColor];[self.view addSubview:view2];    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view2.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];maskLayer.frame = view2.bounds;maskLayer.path = maskPath.CGPath;view2.layer.mask = maskLayer;其中,byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight指定了需要成为圆角的角。该参数是UIRectCorner类型的,可选的值有:* UIRectCornerTopLeft* UIRectCornerTopRight* UIRectCornerBottomLeft* UIRectCornerBottomRight* UIRectCornerAllCorners从名字很容易看出来代表的意思,使用“|”来组合就好了。适应label的长度选择image位置ios6CGSize  atextSize = [titleLabel.text sizeWithFont:[UIFont systemFontOfSize:12]                     constrainedToSize:CGSizeMake(200, 100)                         lineBreakMode:NSLineBreakByTruncatingTail];ios7//// 动态获取高度或者宽度-(CGSize)getHeightOrWeight:(NSString *)Title withFont:(int)font{    NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:font]};    CGSize titleSize = [Title boundingRectWithSize:CGSizeMake(200, 100) options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;        return titleSize;}输出控件frameNSStringFromCGRect(self.loginView.frame)自适应labelios7 +(float)getTextWidth:(float)textHeight text:(NSString *)text fontSize:(float)fontSize isBold:(BOOL)isBold{    if ([text length] == 0) {        return 0;    }    if ([[[[UIDevice currentDevice] systemVersion] substringToIndex:1] intValue] >= 7.0) {        if (isBold) {            return [text boundingRectWithSize:CGSizeMake(MAXFLOAT, textHeight)                                      options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading                                   attributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:fontSize], NSFontAttributeName, nil]                                      context:nil].size.height;        } else {            return [text boundingRectWithSize:CGSizeMake(MAXFLOAT, textHeight)                                      options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading                                   attributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:fontSize], NSFontAttributeName, nil]                                      context:nil].size.width;        }    } else {        if (isBold) {            return [text sizeWithFont:[UIFont boldSystemFontOfSize:fontSize]                    constrainedToSize:CGSizeMake(MAXFLOAT, textHeight)                        lineBreakMode:NSLineBreakByWordWrapping].width;        }        return [text sizeWithFont:[UIFont systemFontOfSize:fontSize]                constrainedToSize:CGSizeMake(MAXFLOAT, textHeight)                    lineBreakMode:NSLineBreakByWordWrapping].width;    }}Ios6//// 动态获取高度或者宽度-(CGSize)getHeightOrWeight:(NSString *)Title withFont:(int)font{//    NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:font]};        CGSize  titleSize = [Title sizeWithFont:[UIFont systemFontOfSize:font]                                    constrainedToSize:CGSizeMake(200, 100)                                        lineBreakMode:NSLineBreakByTruncatingTail];    return titleSize;}为控件增加边框- (void)loadView {     ?   [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation: UIStatusBarAnimationSlide];      ?   UIImageView *contentView = [[MyUIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];  ?   [contentView setImage:[UIImage imageNamed:@"1.jpg"]];  ?   [contentView setUserInteractionEnabled:YES];      ?       ?   self.view=[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];      ?   [self.view addSubview:contentView];      ?   self.view.backgroundColor=[UIColor blackColor];      ?   ?   /*      ?   CALayer *layer=[contentView layer];      ?   [layer setMasksToBounds:YES];      ?   [layer setCornerRadius:10.0];      ?   [layer setBorderWidth:4.0];      ?   */      ?   ?   //为视图增加边框      ?   contentView.layer.masksToBounds=YES;      ?   contentView.layer.cornerRadius=20.0;      ?   contentView.layer.borderWidth=10.0;      ?   contentView.layer.borderColor=[[UIColor blueColor] CGColor];      ?   ?   [contentView release];      ?   ?}NSAttributeString字符串拼接当有收藏无个人中心参考羊绒围巾网iOS 自带的解析json的类。1。数据源是NSData类型的,也可以是NSString类型的,但是NSString类型的可以转换为NSData类型的.     NSString *responseString;    NSData *da= [responseString dataUsingEncoding:NSUTF8StringEncoding];    NSError *error = nil;     id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];     if ([jsonObject isKindOfClass:[NSDictionary class]]){     NSDictionary *dictionary = (NSDictionary *)data;     NSLog(@"Dersialized JSON Dictionary = %@", deserializedDictionary);     }else if ([jsonObject isKindOfClass:[NSArray class]]){     NSArray *nsArray = (NSArray *)jsonObject;     NSLog(@"Dersialized JSON Array = %@", deserializedArray);     } else {     NSLog(@"An error happened while deserializing the JSON data.");     }1.定义一个字符串a, 截取a 的某一个部分,复制给b, b必须是int型  NSString *a = @"1.2.30";    int  b= [[a substringWithRange:NSMakeRange(4,2)] intValue];  NSLog(@"a:%@  \n",a  );  NSLog(@"b:%d",b  ); Output : 2011-07-05 11:49:08.170 Q[4005:207]   a:1.2.30  2011-07-05 11:49:08.172 Q[4005:207]            b:30解析如下:substringWithRange: 专门截取字符串的一块肉           NSMakeRange(4,2)    从第4个字符开始截取,长度为2个字符,(字符串都是从第0个字符开始数的哦~!)             b = [a intValue]; 将 a 转换为 整数型       b = [a floatValue];   将 a 转换为 小数型       b = [a boolValue]; 将 a 转换为 布尔型(true /  false)       b = [a integerValue]; 将 a 转换为 整数型            b = [a longLongValue]; 将 a 转换为 长整型2。 字符串截取到第n位  (substringToIndex: n)(第n 位不算再内) - (void)viewDidLoad{    NSString  *a = @"i like long dress";  NSString *b = [a substringToIndex:4];    NSLog(@"\n b: %@",b);} b: i li  3。字符串从第n 位开始截取,直到最后 (substringFromIndex:n)(包括第 n 位) - (void)viewDidLoad{    NSString  *a = @"i like long dress";    NSString *b = [a substringFromIndex:4];    NSLog(@"\n b: %@",b);}             b: ke long dress   。NSMutableString  为可变的字符串   NSString      为不可变的字符串 -(void)viewDidLoad{   NSMutableString *a = [[NSMutableString  alloc]initWithString:@"123456798"];   NSLog(@" \n a:  %@\n",a);   [a deleteCharactersInRange:NSMakeRange(1,2)];   NSLog(@" \n a:  %@\n",a);    [a release];} 2011-07-05 20:59:34.169 Q[9069:207]   a: 1234567982011-07-05 20:59:34.171 Q[9069:207]   a: 1456798计算两个时间差的两个函数  两个时间之差- (NSString *)intervalFromLastDate: (NSString *) dateString1  toTheDate:(NSString *) dateString2{    NSArray *timeArray1=[dateString1 componentsSeparatedByString:@"."];    dateString1=[timeArray1 objectAtIndex:0];          NSArray *timeArray2=[dateString2 componentsSeparatedByString:@"."];    dateString2=[timeArray2 objectAtIndex:0];    NSLog(@"%@.....%@",dateString1,dateString2);    NSDateFormatter *date=[[NSDateFormatter alloc] init];    [date setDateFormat:@"yyyy-MM-dd HH:mm:ss"];          NSDate *d1=[date dateFromString:dateString1];       NSTimeInterval late1=[d1 timeIntervalSince1970]*1;             NSDate *d2=[date dateFromString:dateString2];       NSTimeInterval late2=[d2 timeIntervalSince1970]*1;             NSTimeInterval cha=late2-late1;    NSString *timeString=@"";    NSString *house=@"";    NSString *min=@"";    NSString *sen=@"";       sen = [NSString stringWithFormat:@"%d", (int)cha%60];    //        min = [min substringToIndex:min.length-7];//    sen=[NSString stringWithFormat:@"%@", sen];             min = [NSString stringWithFormat:@"%d", (int)cha/60%60];//        min = [min substringToIndex:min.length-7];//        min=[NSString stringWithFormat:@"%@", min];          //    小时        house = [NSString stringWithFormat:@"%d", (int)cha/3600];//        house = [house substringToIndex:house.length-7];        house=[NSString stringWithFormat:@"%@", house];       timeString=[NSString stringWithFormat:@"%@:%@:%@",house,min,sen];        [date release];          return timeString;}一个时间距现在的时间- (NSString *)intervalSinceNow: (NSString *) theDate{    NSArray *timeArray=[theDate componentsSeparatedByString:@"."];    theDate=[timeArray objectAtIndex:0];       NSDateFormatter *date=[[NSDateFormatter alloc] init];    [date setDateFormat:@"yyyy-MM-dd HH:mm:ss"];    NSDate *d=[date dateFromString:theDate];       NSTimeInterval late=[d timeIntervalSince1970]*1;          NSDate* dat = [NSDate date];    NSTimeInterval now=[dat timeIntervalSince1970]*1;    NSString *timeString=@"";       NSTimeInterval cha=late-now;       if (cha/3600<1) {        timeString = [NSString stringWithFormat:@"%f", cha/60];        timeString = [timeString substringToIndex:timeString.length-7];        timeString=[NSString stringWithFormat:@"剩余%@分", timeString];           }    if (cha/3600>1&&cha/86400<1) {        timeString = [NSString stringWithFormat:@"%f", cha/3600];        timeString = [timeString substringToIndex:timeString.length-7];        timeString=[NSString stringWithFormat:@"剩余%@小时", timeString];    }    if (cha/86400>1)    {        timeString = [NSString stringWithFormat:@"%f", cha/86400];        timeString = [timeString substringToIndex:timeString.length-7];        timeString=[NSString stringWithFormat:@"剩余%@天", timeString];           }    [date release];    return timeString;}自适应cell NSString *content = [[m_tableviewDataArray objectAtIndex:indexPath.row] objectForKey:@"content"];            content = [NSString stringWithFormat:@"评论:%@",content];            CGSize size = [content sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake(224, 1000) lineBreakMode:NSLineBreakByCharWrapping];                return 43+size.height;  [[[UIApplication sharedApplication] keyWindow] endEditing:YES];当图片请求加密时。。。。   _imageUrl = [[Global shared].textDataUrl stringByAppendingFormat:@"%@%@",@"User_Logo?id=",[[dic objectForKey:@"user"] objectForKey:@"uid"]];            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{                NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:_imageUrl]];                                                //                [self  userHead:dic];                                               UIImage *image = [UIImage imageWithData:[GTMBase64 decodeData:data]];                if (image) {                    dispatch_async(dispatch_get_main_queue(), ^{//                        self.imageData = [GTMBase64 decodeData:image];                        cell.headImageView.image = image;                    });                }                                            });汽包拉伸UIImage * image = [UIImage imageNamed:@"img_dialog.9.png"];            image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(5, 5, 0, 5) resizingMode:UIImageResizingModeStretch];//            UIImageView *imageView = [[UIImageView alloc] initWithImage:image];            [cell.contentBgImage setImage:image];通过手势移除键盘- (void)viewDidLoad?{?[super viewDidLoad];?UITapGestureRecognizer *tapGr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];?tapGr.cancelsTouchesInView = NO;?[self.view addGestureRecognizer:tapGr];?}?-(void)viewTapped:(UITapGestureRecognizer*)tapGr{?[activitySearchBar resignFirstResponder];?}webView改变字体大小  NSString*str=[NSString stringWithFormat:@"document.body.style.fontSize=%f;",12.0];    [webView stringByEvaluatingJavaScriptFromString:str];xcode路径?mac系统如何显示和隐藏文件苹果Mac OS X操作系统下,隐藏文件是否显示有很多种设置方法,最简单的要算在Mac终端输入命令。显示/隐藏Mac隐藏文件命令如下(注意其中的空格并且区分大小写):显示Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool true隐藏Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool false   NSString *string = @"你知道怎么在一个设置不同的颜色嘛?";    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:string];    //设置颜色(NSForegroundColorAttributeName代表要设置颜色, value代表值, range 代表范围)    /**     其他设置:     1.NSForegroundColorAttributeName //颜色     2.NSFontAttributeName //字体     3.NSBackgroundColorAttributeName //背景色     //还有其他的很多的属性,可以自己去看苹果的API,这里不再详述     */    [attrString addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(1, 7)];证书问题pro身份过期可以改下名字重新上传?有时候在画cell的时候,里面的控件我会给它设置tag,用来在cellForRowAtIndexPath中获取每个cell的子控件,如果子控件有个UIButton,你给它设置targeta后,在响应的方法里没办法分是从哪一个cell的button触发的,因为所有的cell的那个UIbutton的tag是一样的。??既然不许改变tag,有没有其他办法知道它的父容器Cell的行数呢?知道行数了不会知道是哪一个cell的Button触发的。?方法1:?NSString* cellStr1 = [NSString stringWithFormat:@"%d", indexPath.row];?[btn_attention setTitle:cellStr1 forState:UIControlEventTouchCancel];??获取title,并转为行数:??NSString* cellIndex = [sender titleForState:UIControlEventTouchCancel];?int tag =[cellIndex intValue];???方法2:? UITableViewCell * cell = (UITableViewCell *)[[sender superview] superview];?   NSIndexPath * path = [self.baseTableView indexPathForCell:cell];?   //获取按钮所在的cell的row? BnetBillMode = [self.tableArray objectAtIndex:path.row];???方法3:?? [cell.button addTarget:self action:@selector(didTapButton:)   forControlEvents:UIControlEventTouchUpInside];?那么点击button时就会调用?- (void)didTapButton:(UIButton *)sender?      剩下的就是如何通过这个sender获得它所在的cell。我们这么实现这个方法,??- (void)didTapButton:(UIButton *)sender?{?  CGRect buttonRect = sender.frame;?  for (CustomCell *cell in [self.baseTableView visibleCells])?  {?    if (CGRectIntersectsRect(buttonRect, cell.frame))?    {?      //cell就是所要获得的?    }?  }?}查找某个数组中包含某个字符串    NSArray * array = [NSArray arrayWithObjects:@"a",@"aa",@"1a",@"ea",@"add",@"", nil];    for (NSString * a in array) {        NSRange  rang = [a rangeOfString:@"a"];        if (rang.length>0) {            NSLog(@"%@",a);        }    }webViewCell 调整高度- (void)webViewDidFinishLoad:(UIWebView *)webView {        for (UIScrollView *view in webView.subviews) {                // int miHeight;                if ([view isKindOfClass:[UIScrollView class]]) {                        NSString *str = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"];                        int iHeight = [str intValue];                        if (iHeight<10) {                                iHeight = 10;                            }            webHeight = iHeight;            webView.frame = CGRectMake(0, 166, 320, webHeight+166);            //            NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys: nil];//            //            [dic setValue:[NSString stringWithFormat:@"%d",iHeight] forKey:[NSString stringWithFormat:@"%d",webView.tag]];                        [self OnLoadFinish:(WebViewCell *)webView.superview.superview];                    }            }            }- (void)OnLoadFinish:(WebViewCell *)sender {        [m_tableview beginUpdates];            //..........            [m_tableview endUpdates];    }NSMutableAttributedString 改变部分颜色self.title = @"For iOS 6 & later";NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Using NSAttributed String"];[str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,5)];[str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6,12)];[str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(19,6)];[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial-BoldItalicMT" size:30.0] range:NSMakeRange(0, 5)];[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:30.0] range:NSMakeRange(6, 12)];[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Courier-BoldOblique" size:30.0] range:NSMakeRange(19, 6)];attrLabel.attributedText = str;nsrang确定字符串的位置- (void)viewDidLoad{    [super viewDidLoad];    //抽取指定范围的字符串    NSString *string1 = @"0123456789";    NSRange range1 = NSMakeRange(0, 4);//NSMakeRange这个函数的作用是从第0位开始计算,长度为4    NSLog(@"从第0个字符开始,长度为4的字符串是:%@",[string1 substringWithRange:range1]);    NSLog(@"抽取从头开始到第4个字符:%@",[string1 substringToIndex:4]);    NSLog(@"抽取从第6个字符开始到末尾:%@",[string1 substringFromIndex:6]);        NSString *string2 = @"wo shi xiao bai zhu";    NSRange range2 = [string2 rangeOfString:@"bai"];    if (range2.length > 0) {        NSLog(@"{字符串中“bai”的位置,长度}==%@",NSStringFromRange(range2));    }    //判断在一串字符串中是否找到某个字符串    NSRange range3 = [string2 rangeOfString:@"zhu"];    if (range3.location != NSNotFound) {        NSLog(@"找到了@“zhu”这个字符串!");    }    else        NSLog(@"没找到!");}判断是否为空+ (BOOL)arrayNOTNull:(id)object{    if ((NSNull *)object == [NSNull null]){        return NO;    }    return YES;}+ (BOOL)isNOTNull:(id)object{    // 判断是否为空串    if ([object isEqual:[NSNull null]]) {        return NO;    }    else if ([object isKindOfClass:[NSNull class]])    {        return NO;    }    else if (object==nil){        return NO;    }    else if ([(NSString *)object isEqualToString:@""] ||[(NSString *)object isEqualToString:@" "]){        return NO;    }    return YES;}webview链接跳转-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{    if (navigationType == UIWebViewNavigationTypeLinkClicked)    {        NSURL *url =[request URL];        NSString *curUrl = [url absoluteString];        NSLog(@"............%@",curUrl);        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:curUrl]];        return false;    }    return  YES;}scrollView 的偏移量  CGFloat pageWidth = scrollView.frame.size.width;    int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;    downpageControl.currentPage = page;viewControl的view放到view上需要当前view control指针指向他判断团购时间- (NSString *)intervalFromLastDate1: (NSString *) dateString1{    NSArray *timeArray1=[dateString1 componentsSeparatedByString:@"."];    dateString1=[timeArray1 objectAtIndex:0];            NSDate *  currentTime=[NSDate date];    NSDateFormatter *date=[[NSDateFormatter alloc] init];    [date setDateFormat:@"yyyy-MM-dd"];                NSString *  locationString=[date stringFromDate:currentTime];        NSLog(@"locationString:%@",locationString);        //    [date release];             NSString * startDate = self.stateArray[0];    NSDate *d1=[date dateFromString:dateString1];        NSTimeInterval late1=[d1 timeIntervalSince1970]*1;                NSDate *d2=[date dateFromString:startDate];        NSTimeInterval late2=[d2 timeIntervalSince1970]*1;                NSTimeInterval cha=late1-late2;    NSString *timeString=@"";                if (cha<0) {                timeString=[NSString stringWithFormat:@"未开始"];            }            [date release];            return timeString;}判断字典为空(    1.    NSString *value = [dictionary objectForKey:@"First"];     2.    if ((NSNull *)value == [NSNull null]) {     3.    }     #遍历找到btn    UITableViewCell * cell = (UITableViewCell*)[btn superview];        for (UIButton * btn1 in [cell subviews]) {        if ([btn1 isMemberOfClass:[UIButton class]]) {            if (btn1==btn) {                 btn1.backgroundColor = [UIColor redColor];            }            else            {                btn1.backgroundColor = [UIColor grayColor];            }                    }    } //气泡拉伸textBackImageView.image = [[UIImage imageNamed:@"ReceiverTextNodeBkgHL_ios7"]resizableImageWithCapInsets:UIEdgeInsetsMake(28, 18, 25, 10)] ;

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
iOS 第6项目个别技术点
Objective-C的字符串处理类NSString
iOS NSString的常用用法
Objective
iOS微信支付开发 | iOS开发
!!OC中copy的使用
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服