日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁(yè) > 嵌入式 > 嵌入式軟件
[導(dǎo)讀] 1、如果在程序中想對(duì)某張圖片進(jìn)行處理的話(得到某張圖片的一部分)可一用以下代碼:UIImage *image = [UIImage imageNamed:filename];CGImageRef imageRef = image.CGImage

 1、如果在程序中想對(duì)某張圖片進(jìn)行處理的話(得到某張圖片的一部分)可一用以下代碼:

UIImage *image = [UIImage imageNamed:filename];

CGImageRef imageRef = image.CGImage;

CGRect rect = CGRectMake(origin.x, origin.y ,size.width, size.height);

CGImageRef imageRefRect = CGImageCreateWithImageInRect(imageRef, rect);

UIImage *imageRect = [[UIImage alloc] initWithCGImage:imageRefRect];

2、判斷設(shè)備是iphone還是iphone4的代碼:

#define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)

3、判斷郵箱輸入的是否正確:

- (BOOL) validateEmail: (NSString *) candidate {

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

}

4、如何把當(dāng)前的視圖作為照片保存到相冊(cè)中去:

#import

UIGraphicsBeginImageContext(currentView.bounds.size); //currentView 當(dāng)前的view

[currentView.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

5、本地通知(類似于push通知)按home鍵到后臺(tái) 十秒后觸發(fā):

UILocalNotification *notification=[[UILocalNotification alloc] init];

if (notification!=nil) {

NSLog(@">> support local notification");

NSDate *now=[NSDate new];

notification.fireDate=[now addTimeInterval:10];

notification.timeZone=[NSTimeZone defaultTimeZone];

notification.alertBody=@"該去吃晚飯了!";

[[UIApplication sharedApplication].scheduleLocalNotification:notification];

}

6、捕獲iphone通話事件:

CTCallCenter *center = [[CTCallCenter alloc] init];

center.callEventHandler = ^(CTCall *call)

{

NSLog(@"call:%@", call.callState);

}

7、iOS 4 引入了多任務(wù)支持,所以用戶按下 “Home” 鍵以后程序可能并沒(méi)有退出而是轉(zhuǎn)入了后臺(tái)運(yùn)行。如果您想讓應(yīng)用直接退出,最簡(jiǎn)單的方法是:在 info-plist 里面找到 Application does not run in background 一項(xiàng),勾選即可。

8、使UIimageView的圖像旋轉(zhuǎn):

float rotateAngle = M_PI;

CGAffineTransform transform =CGAffineTransformMakeRotation(rotateAngle);

imageView.transform = transform;

9、設(shè)置旋轉(zhuǎn)的原點(diǎn):

#import

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg.png"]];

imageView.layer.anchorPoint = CGPointMake(0.5, 1.0);

10、實(shí)現(xiàn)自定義的狀態(tài)欄(遮蓋狀態(tài)欄):

CGRect frame = {{0, 0}, {320, 20}};

UIWindow* wd = [[UIWindow alloc] initWithFrame:frame];

[wd setBackgroundColor:[UIColor clearColor]];

[wd setWindowLevel:UIWindowLevelStatusBar];

frame = CGRectMake(100, 0, 30, 20);

UIImageView* img = [[UIImageView alloc] initWithFrame:frame];

[img setContentMode:UIViewContentModeCenter];

[img setImage:[UIImage imageNamed:@"00_0103.png"]];

[wd addSubview:img];

[wd makeKeyAndVisible];

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:2];

frame.origin.x += 150;

[img setFrame:frame];

[UIView commitAnimations];

11、在程序中實(shí)現(xiàn)電話的撥打:

//添加電話圖標(biāo)按鈕

UIButton *btnPhone = [[UIButton buttonWithType:UIButtonTypeCustom] retain];

btnPhone.frame = CGRectMake(280,10,30,30);

UIImage *image = [UIImage imageNamed:@"phone.png"];

[btnPhone setBackgroundImage:image forState:UIControlStateNormal];

//點(diǎn)擊撥號(hào)按鈕直接撥號(hào)

[btnPhone addTarget:self action:@selector(callAction:event:)forControlEvents:UIControlEventTouchUpInside];

[cell.contentView addSubview:btnPhone]; //cell是一個(gè)UITableViewCell

//定義點(diǎn)擊撥號(hào)按鈕時(shí)的操作

- (void)callAction:(id)sender event:(id)event{

NSSet *touches = [event allTouches];

UITouch *touch = [touches anyObject];

CGPoint currentTouchPosition = [touch locationInView:self.listTable];

NSIndexPath *indexPath = [self.listTable indexPathForRowAtPoint: currentTouchPosition];

if (indexPath == nil) {

return;

}

NSInteger section = [indexPath section];

NSUInteger row = [indexPath row];

NSDictionary *rowData = [datas objectAtIndex:row];

NSString *num = [[NSString alloc] initWithFormat:@"tel://%@",number]; //number為號(hào)碼字符串

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:num]]; //撥號(hào)

}

12、更改iphone的鍵盤顏色:[!--empirenews.page--]

1.只有這2種數(shù)字鍵盤才有效果。UIKeyboardTypeNumberPad,UIKeyboardTypePhonePad

2. keyboardAppearance = UIKeyboardAppearanceAlert

- (void)textViewDidBeginEditing:(UITextView *)textView{

NSArray *ws = [[UIApplication sharedApplication] windows];

for(UIView *w in ws){

NSArray *vs = [w subviews];

for(UIView *v in vs)

{

if([[NSString stringWithUTF8String:object_getClassName(v)] isEqualToString:@"UIKeyboard"])

{

v.backgroundColor = [UIColor redColor];

}

}

}

13、設(shè)置時(shí)區(qū)

NSTimeZone *defaultTimeZone = [NSTimeZone defaultTimeZone];

NSTimeZone *tzGMT = [NSTimeZone timeZoneWithName:@"GMT"];

[NSTimeZone setDefaultTimeZone:tzGMT];

上面兩個(gè)時(shí)區(qū)任意用一個(gè)。

14、Ipad隱藏鍵盤的同時(shí)觸發(fā)方法。

[[NSNotificationCenter defaultCenter] addObserver:self

selector:@selector(keyboardWillHide:)

name:UIKeyboardWillHideNotification

object:nil];

- (IBAction)keyboardWillHide:(NSNotification *)note

14、在一個(gè)程序中打開另一個(gè)程序的方法。

http://www.cocoachina.com/iphonedev/sdk/2010/0322/768.html

15、計(jì)算字符串的字?jǐn)?shù)

-(int)calculateTextNumber:(NSString *)text

{

float number = 0.0;

int index = 0;

for (index; index < [text length]; index++)

{

NSString *protoText = [text substringToIndex:[text length] - index];

NSString *toChangetext = [text substringToIndex:[text length] -1 -index];

NSString *charater;

if ([toChangetext length]==0)

{

charater = protoText;

}

else

{

NSRange range = [text rangeOfString:toChangetext];

charater = [protoText stringByReplacingCharactersInRange:range withString:@""];

}

NSLog(charater);

if ([charater lengthOfBytesUsingEncoding:NSUTF8StringEncoding] == 3)

{

number++;

}

else

{

number = number+0.5;

}

}

return ceil(number);

}

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉