新手入门常用的iPhone代码Word文件下载.docx
- 文档编号:16722913
- 上传时间:2022-11-25
- 格式:DOCX
- 页数:17
- 大小:26.07KB
新手入门常用的iPhone代码Word文件下载.docx
《新手入门常用的iPhone代码Word文件下载.docx》由会员分享,可在线阅读,更多相关《新手入门常用的iPhone代码Word文件下载.docx(17页珍藏版)》请在冰豆网上搜索。
*format
[[NSDateFormatter
alloc]
init];
[format
setDateFormat:
YYYY/MM/dd
hh:
mm:
ss"
s
stringFromDate:
d];
release];
return
s;
}
各地时区获取:
代码
*nowDate
new];
*formatter
[formatter
yyyy/MM/dd
HH:
//
根据时区名字获取当前时间,如果该时区不存在,默认获取系统当前时区的时间
NSTimeZone*
timeZone
[NSTimeZone
timeZoneWithName:
Europe/Andorra"
setTimeZone:
timeZone];
//获取所有的时区名字
NSArray
*array
knownTimeZoneNames];
NSLog(@"
array:
array);
//for循环
for(int
i=0;
i<
[array
count];
i++)
objectAtIndex:
i]];
*locationTime
nowDate];
时区名字:
:
时区当前时间:
[array
i],locationTime);
//NSLog(@"
timezone
name
is:
i]);
}
//快速枚举法
for(NSString
*timeZoneName
in
array){
timeZoneName]];
%@,%@"
timeZoneName,[formatter
nowDate]);
[nowDate
获取毫秒时间:
*dateFormatter
[dateFormatter
setDateStyle:
NSDateFormatterMediumStyle];
setTimeStyle:
NSDateFormatterShortStyle];
//[dateFormatter
]
yyyy-MM-dd
ss.SSS"
Date%@"
date]]);
3.
NSCalendar用法:
getWeek:
NSCalendar
*calendar
[[NSCalendar
initWithCalendarIdentifier:
NSGregorianCalendar];
unsigned
units
NSYearCalendarUnit
|
NSMonthCalendarUnit
NSDayCalendarUnit
NSWeekdayCalendarUnit;
NSDateComponents
*components
[calendar
components:
fromDate:
switch
([components
weekday])
case
2:
Monday"
break;
3:
Tuesday"
4:
Wednesday"
5:
Thursday"
6:
Friday"
7:
Saturday"
1:
Sunday"
default:
No
Week"
用components,我们可以读取其他更多的数据。
4.用Get方式读取网络数据:
将网络数读取为字符串
-
(NSString
getDataByURL:
url
[[NSString
initWithData:
[NSData
dataWithContentsOfURL:
[NSURL
URLWithString:
[url
stringByAddingPercentEscapesUsingEncoding:
NSUTF8StringEncoding]]]
encoding:
//读取网络图片
(UIImage
getImageByURL:
[[UIImage
NSUTF8StringEncoding]]]];
5.多线程NSThread用法:
[NSThread
detachNewThreadSelector:
@selector(scheduleTask)
toTarget:
self
withObject:
nil];
-(void)
scheduleTask
//create
a
pool
NSAutoreleasePool
*pool
[[NSAutoreleasePool
//release
the
pool;
[pool
//如果有参数,则这么使用:
@selector(scheduleTask:
)
date]];
scheduleTask:
mdate
//注意selector里有冒号。
//在线程里运行主线程里的方法
[selfperformSelectorOnMainThread:
@selector(moveToMain)
nil
waitUntilDone:
FALSE];
6.定时器NSTimer用法:
一个可以自动关闭的Alert窗口
UIAlertView
*alert
[[UIAlertView
initWithTitle:
message:
[@"
一个可以自动关闭的Alert窗口"
delegate:
cancelButtonTitle:
//NSLocalizedString(@"
OK"
//取消任何按钮
otherButtonTitles:
//[alert
setBounds:
CGRectMake(alert.bounds.origin.x,
alert.bounds.origin.y,
alert.bounds.size.width,
alert.bounds.size.height+30.0)];
[alert
show];
UIActivityIndicatorView
*indicator
[[UIActivityIndicatorView
initWithActivityIndicatorStyle:
UIActivityIndicatorViewStyleWhiteLarge];
Adjust
indicator
so
it
is
up
few
pixels
from
bottom
of
alert
indicator.center
CGPointMake(alert.bounds.size.width/2,
alert.bounds.size.height-40.0);
[indicator
startAnimating];
insertSubview:
atIndex:
0];
[NSTimer
scheduledTimerWithTimeInterval:
3.0f
target:
self
selector:
@selector(dismissAlert:
)
userInfo:
[NSDictionary
dictionaryWithObjectsAndKeys:
alert,
alert"
testing
"
key"
nil]
//如果不用传递参数,那么可以将此项设置为nil.
repeats:
NO];
release
);
dismissAlert:
(NSTimer
*)timer{
timer"
NSLog([[timer
userInfo]
objectForKey:
]);
[[timer
dismissWithClickedButtonIndex:
0
animated:
YES];
定时器停止使用:
[timer
invalidate];
timer
nil;
7.用户缺省值NSUserDefaults读取:
//得到用户缺省值
NSUserDefaults
*defs
[NSUserDefaults
standardUserDefaults];
//在缺省值中找到AppleLanguages,
返回值是一个数组
NSArray*
languages
[defs
AppleLanguages"
all
language语言
languages);
//在得到的数组中的第一个项就是用户的首选语言了
首选语言
[languages
0]);
//get
language
&
country
code
NSLocale
*currentLocale
[NSLocale
currentLocale];
Language
Code
[currentLocale
NSLocaleLanguageCode]);
Country
NSLocaleCountryCode]);
8.View之间切换的动态效果设置:
SettingsController
*settings
[[SettingsController
alloc]initWithNibName:
SettingsView"
bundle:
settings.modalTransitionStyle
UIModalTransitionStyleFlipHorizontal;
//水平翻转
[self
presentModalViewController:
settings
[settings
9.NSScrollView滑动用法:
scrollViewDidScroll:
(UIScrollView
*)scrollView{
正在滑动中..."
//用户直接滑动NSScrollView,可以看到滑动条
scrollViewDidEndDecelerating:
*)scrollView
通过其他控件触发NSScrollView滑动,看不到滑动条
(void)
scrollViewDidEndScrollingAnimation:
10.读取全局的Delegate:
KiloNetAppDelegate
*appdelegate
(KiloNetAppDelegate
*)[[UIApplication
sharedApplication]
delegate];
11.键盘处理系列
//set
UIKeyboard
to
different
text
field
when
you
press
return
//switch
textField
your
textfield
[textField
becomeFirstResponder];
12.半透明层的实现:
半透明层
+(void)showWaiting:
(UIView
*)parent
int
width
32,
height
32;
CGRect
frame
[parent
frame];
//[[UIScreen
mainScreen]
applicationFrame];
x
frame.size.width;
y
frame.size.height;
CGRectMake((x
width)
/
2,
(y
height)
width,
height);
UIActivityIndicatorView*
progressInd
initWithFrame:
[progressInd
progressInd.activityIndicatorViewStyle
UIActivityIndicatorViewStyleWhiteLarge;
140)/2,
2
+
height,
140,
30);
UILabel
*waitingLable
[[UILabel
waitingLable.text
Proccesing..."
waitingLable.textColor
[UIColor
whiteColor];
waitingLable.font
[UIFont
systemFontOfSize:
15];
waitingLable.backgroundColor
clearColor];
UIView
*theView
[[UIView
theView.backgroundColor
blackColor];
theView.alpha
0.8;
[theView
addSubview:
progressInd];
waitingLable];
[waitingLable
setTag:
9999];
theView];
+(void)hideWaiting:
[[parent
viewWithTag:
9999]
removeFromSuperview];
13.设置View的圆角:
首先应用
#import
<
QuartzCore/QuartzCore.h>
view.layer.cornerRadius
10;
view.layer.masksToBounds
YES;
14.UIWebView显示本地图片(目前有点问题,无法正确显示图片):
*imagePath
[[NSBundle
mainBundle]
resourcePath];
imagePath
[imagePath
stringByReplacingOccurrencesOfString:
/"
withString:
//"
%20"
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 新手入门 常用 iPhone 代码