小知识

(1)从safari打开链接

[[UIApplication sharedApplication] openURL:url];

(3)SEL

      
Objective-C在编译的时候,会根据方法的名字(包括参数序列),生成一个用 来区分这个方法的唯一的一个ID,这个ID就是SEL类型的。我们需要注意的是,只要方法的名字(包括参数序列)相同,那么它们的ID都是相同的。就是 说,不管是超类还是子类,不管是有没有超类和子类的关系,只要名字相同那么ID就是一样的。

       我们可以方便的通过方法的名字,获取到方法的ID也就是我们所说的SEL,反之亦然。具体的使用方法如下: 

SEL 变量名 = @selector(方法名字);   
SEL 变量名 = NSSelectorFromString(方法名字的字符串);   
NSString *变量名 = NSStringFromSelector(SEL参数);

       这样的机制大大的增加了我们的程序的灵活性,我们可以通过给一个方法传递SEL参数,让这个方法动态的执行某一个方法;我们也可以通过配置文件指定需要执行的方法,程序读取配置文件之后把方法的字符串翻译成为SEL变量然后给相应的对象发送这个消息。 

  从效率的角度上来说,执行的时候不是通过方法名字而是方法ID也就是一个整数来查找方法,由于整数的查找和匹配比字符串要快得多,所以这样可以在某种程度上提高执行的效率。


(4)禁止锁屏

[[UIApplication sharedApplication] setIdleTimerDisabled: YES];

(5)判断UIViewController是push的还是present进去的:

   int n = [self.navigationController.childViewControllers count];
    if (n>1)
    {
        //push
    }
    else
    {
       //present
    }

(6)View圆角

(记得引入框架:#import <QuartzCore/QuartzCore.h>)

[headImageView.layer setMasksToBounds:YES];
[headImageView.layer setCornerRadius:4];

setMasksToBounds:方法告诉layer将位于它之下的layer都遮盖住。这是必须的,这样会使圆角不被遮,但是这样会导致阴影效果没有(就是说圆角个阴影是不能同事存在的),不过再添加一个SubLayer,也可以添加阴影。

 

 

(7)阴影

//阴影边界

[headImageView.layer setShodowOffSet:CGSize(1,1)];

//阴影颜色

[headImageView.layer setShowColor:[UIColor whiteColor].CGColor];

//透明度

[headImageView.layer setShadowOpacity:0.7];

(8)判断一个特定的点是否落在区域内:

CGRectContainsPoint(CGRect rect, CGPoint point)

Returns whether a rectangle contains a specified point.

bool CGRectContainsPoint (CGRect
rect,
CGPoint
point
);

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint point = [touch locationInView:self];
    
    if (CGRectContainsPoint(self.thumb.frame, point))
    {
        //point在rect中的动作
    }
}

(9)关于输出函数

(转自:http://blog.csdn.net/tangren03/article/details/7741853)

     根据不同的输出格式输出不同的值 (%d :整形 ,%@:对象<发送description消息>,%s:字符串)

     NSlog(@“The result is %d”,intNum); 

     

     CF代表Core Foundation (Cocoa)

     CFShow发送description给它显示的对象,CFShow打印的信息不会显示时间戳,NSLog会显示,同时CFShow不需要格式字符串,它只能用于对象

     CFShow(obj);


(10)属性

(转自:http://blog.csdn.net/tangren03/article/details/7741853)

     支持点表示法:myTableViewCell.textLabel.text = @"hello" 等价于 [[myTableViewCell textLabel] setText:@"hello"];


     使用属性生成器 property

     在h文件中声明: @property int year

     在m文件中合成生成器:@synthesize year

     使用 obj.year = 1999 相当于调用了 [obj setYear:1999];


     可以自定义取值方法和赋值方法(getter and setter)

     -(int)year

     {

          return year;

     }


     - (void) setYear : (int) newYear

     {

          //此处添加了一些基本的内存管理方法,保留新的值,释放以前的值

          if(newYear != year)

          {

               [year release];

               year = [newYear retain];

          }

     }


     也可以绕过oc的命名约定,自己指定getter和setter方法的名称;

     @property(getter = isExist,setter = setExist:) BOOL exist;

     @synthesize exist;

     使用过程中既可以使用新定义的方法名,也可以使用以前的方法(点表示法)

(11)判断邮箱号是否有效

-(BOOL)isValidateEmail:(NSString *)email
{
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    return [emailTest evaluateWithObject:email];
}

(12)nil,Nil,Null,NSNull,null区别

nil: A null pointer to an Objective-C object. ( #define nil((id)0) )
nil 是一个对象值。

Nil: A null pointer to an Objective-C class.

NULL: A null pointer to anythingelse. ( #define NULL ((void*)0) )
NULL是一个通用指针(泛型指针)。

NSNull: A class defines a singletonobject used to represent nullvalues in collection objects (which don't allow nilvalues).
[NSNull null]: The singleton instance of NSNull.
[NSNull null]是一个对象,他用在不能使用nil的场合。
因为在NSArray和NSDictionary中nil中有特殊的含义(表示列表结束),所以不能在集合中放入nil值。如要确实需要存储一个表示“什么都没有”的值,可以使用NSNull类。NSNull只有一个方法:
+ (NSNull *) null;

(13)检测系统版

    float version = [[[UIDevice currentDevice] systemVersion] floatValue];

//下面是ios内其他相关信息的判断方法


获取进程信息和设备信息(包括设备类型,序列号,ios版本等)
[[NSProcessInfo processInfo] globallyUniqueString],
[[NSProcessInfo processInfo] hostName],
[[NSProcessInfo processInfo] operatingSystemName],
[[NSProcessInfo processInfo] operatingSystemVersionString],
[[NSProcessInfo processInfo] physicalMemory],
[[NSProcessInfo processInfo] processName]);
——————————————————————————————
[UIDevice currentDevice].uniqueIdentifier,
[UIDevice currentDevice].name,
[UIDevice currentDevice].systemName,
[UIDevice currentDevice].systemVersion,
[UIDevice currentDevice].model,
[UIDevice currentDevice].localizedModel,
[UIDevice currentDevice].batteryLevel
___________________________________________________
NSLog([[UIDevice currentDevice] name]); // Name of the phone as named by user
NSLog([[UIDevice currentDevice] uniqueIdentifier]); // A GUID like string
NSLog([[UIDevice currentDevice] systemName]); // "iPhone OS"
NSLog([[UIDevice currentDevice] systemVersion]); // "2.2.1"
NSLog([[UIDevice currentDevice] model]); // "iPhone" on both devices
NSLog([[UIDevice currentDevice] localizedModel]); // "iPhone" on both devices

(14)获取活动界面

+(UIViewController*) topMostController {
    UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
    while (topController.presentedViewController) {
        topController = topController.presentedViewController;
    } return topController;
}

(15)模拟器截图快捷键

command+s。

   (16)修改cell.imageView.frame大小:

The best way is to add -
(void)layoutSubviews
 to your cell subclass like this:

- (void)layoutSubviews {
    [super layoutSubviews];
    self.imageView.frame = CGRectMake(0.0f , 0.0f, 32.0f, 32.0f);
}

(17)iOS中使用blend改变图片颜色

http://onevcat.com/2013/04/using-blending-in-ios/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值