1.UIDatePicker 简单使用。
NSLocal NSTimeZone
2.UIDevice
-近距离传感器使用如打电话时屏幕的亮度变化。
@property(nonatomic,getter=isProximityMonitoringEnabled)BOOL proximityMonitoringEnabled
@property(nonatomic,readonly) BOOL proximityStateNS_AVAILABLE_IOS(3_0); // always returns NO if no proximity detector
1)使用
if
区分目前UI_USER_INTERFACE_IDIOM()有2个返回值
UI_USER_INTERFACE_IDIOM() ==
UI_USER_INTERFACE_IDIOM() ==
2)使用
3)使用userInterfaceIdiom
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
NSLog(@"this device is iphone");
}else if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad){
NSLog(@"this device is ipad");
}
-检测设备当前的方向
1) 使用系统定义的宏
#define UIDeviceOrientationIsPortrait(orientation) ((orientation) == UIDeviceOrientationPortrait || (orientation) == UIDeviceOrientationPortraitUpsideDown)
#define UIDeviceOrientationIsLandscape(orientation) ((orientation) == UIDeviceOrientationLandscapeLeft || (orientation) == UIDeviceOrientationLandscapeRight)
2) orientation
switch ([UIDevice currentDevice].orientation) {
case UIDeviceOrientationPortrait:
break;
case UIDeviceOrientationLandscapeLeft:
break;
default:
break;
}
3.UIFont and UIFontDescriptor(ios7)
-ios7中最新的设置font属性的方法
原文出处:http://blog.youkuaiyun.com/conpgy/article/details/24463397
4.UIGeometry
-NSString、NSValu 与CGPoint、CGSize、CGRect等结构体之间转换的API
UIKIT_EXTERN NSString *NSStringFromCGPoint(CGPoint point);
UIKIT_EXTERN NSString *NSStringFromCGSize(CGSize size);
UIKIT_EXTERN NSString *NSStringFromCGRect(CGRect rect);
UIKIT_EXTERN NSString *NSStringFromCGAffineTransform(CGAffineTransform transform);
UIKIT_EXTERN NSString *NSStringFromUIEdgeInsets(UIEdgeInsets insets);
UIKIT_EXTERN CGPoint CGPointFromString(NSString *string);
UIKIT_EXTERN CGSize CGSizeFromString(NSString *string);
UIKIT_EXTERN CGRect CGRectFromString(NSString *string);
UIKIT_EXTERN CGAffineTransform CGAffineTransformFromString(NSString *string);
UIKIT_EXTERN UIEdgeInsets UIEdgeInsetsFromString(NSString *string);
5.UIImage
-枚举值点击打开链接
typedef NS_ENUM(NSInteger, UIImageResizingMode) {
UIImageResizingModeTile, //平铺
UIImageResizingModeStretch,//拉伸
};
typedef NS_ENUM(NSInteger, UIImageRenderingMode) {
UIImageRenderingModeAutomatic, // 根据图片的使用环境和所处的绘图上下文自动调整渲染模式。
UIImageRenderingModeAlwaysOriginal, // 始终绘制图片原始状态,不使用Tint Color。
UIImageRenderingModeAlwaysTemplate, // 始终根据Tint Color绘制图片,忽略图片的颜色信息。
} NS_ENUM_AVAILABLE_IOS(7_0);
-图片拉伸
- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets NS_AVAILABLE_IOS(5_0); // create a resizable version of this image. the interior is tiled when drawn.
- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode NS_AVAILABLE_IOS(6_0); // the interior is resized according to the resizingMode
具体方法见链接http://justsee.iteye.com/blog/1973358
-图片动画
UIImage还可以加载多张图片,并按指定时间间隔依次显示多张图片,这就可以非常方便地实现动画效果。UImage提供了如下方法来加载多张图片实现动画。
Ø + animatedImageNamed:duration::根据指定的图片名来加载系列图片。例如,调用该方法时的第一个参数名为butterfly,该方法将会自动加载butterfly0.png、butterfly1.png、butterfly2.png等图片。
Ø + animatedImageWithImages:duration::该方法需要传入一个NSArray作为多张动画图片。该NSArray中的每个元素都是UIImage对象。
Ø - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingModeNS_AVAILABLE_IOS(6_0);该方法动态的调整图片大小。
实例:蝴蝶飞舞
@implementation FKViewController
UIImageView* iv; // 定义显示图片的UIImageView控件
NSTimer* timer; // 定义定时器
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor]; // 设置背景色为白色
iv = [[UIImageView alloc]
initWithFrame:CGRectMake(0 , 30 , 41 , 43)]; // 创建UIImageView控件
iv.image = [UIImage animatedImageNamed:@"butterfly_f" duration:0.6];
// 使用UIImageView加载文件名以butterfly_f开头的多张图片
[self.view addSubview: iv]; // 将UIImageView添加到系统界面上
// 启动NSTimer定时器来改变UIImageView的位置
timer = [NSTimer scheduledTimerWithTimeInterval:0.1
target:self selector:@selector(changePos)
userInfo:nil repeats:YES];
}
- (void) changePos
{
CGPoint curPos = iv.center;
int y = arc4random() % 10 - 5; // 计算-5~5之间的一个随机数
// 当curPos的x坐标已经超过了屏幕的宽度
if(curPos.x > [UIScreen mainScreen].bounds.size.width)
{
iv.center = CGPointMake(0, 30); // 控制蝴蝶再次从屏幕左侧开始移动
}
// 通过修改iv的center属性来改变iv控件的位置
iv.center = CGPointMake(curPos.x + 4, curPos.y + y);
}
@end