參考了蘋果官方文件,和一些網路資訊,整理了3D touch的用法
3D touch整理
使用範例
實作的時候,發現preview action sheet的實作要在preview view controller的那個class才能work
2015年10月30日
2012年12月18日
[iPhone]Background Setting
今天在設定UITableView的background,發現了如果設定image為table view的background,
每個section之間會有被截斷的感覺,
測試之後發現直接設定UIWindow 的background,接下來把所有的view背景設為透明才是最快變換背景的方法。
在didFnishLaunchingWithOptions裡面加上
[window setBackgroundColor: [[UIClolor alloc] initWithPatternImage:[UIImage imageName:@"imagename.png" ] ] ];
接下來在每一個頁面設定background為clearColor,就完成背景的更改囉。
2012年10月4日
[iPhone]繼承UIView
先建立繼承UIView的class,
接下來建立xib檔,並在xib中設定class為剛剛建立的class,
把xib內的物件和class link 起來,
並在initWithFrame中加入
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
NSArray *viewXib = [[NSBundle mainBundle] loadNibNamed:@"viewer" owner:self options:nil];
self = [viewXib objectAtIndex:0];
}
return self;
}
接下來建立xib檔,並在xib中設定class為剛剛建立的class,
把xib內的物件和class link 起來,
並在initWithFrame中加入
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
NSArray *viewXib = [[NSBundle mainBundle] loadNibNamed:@"viewer" owner:self options:nil];
self = [viewXib objectAtIndex:0];
}
return self;
}
2012年9月6日
[iPhone]多國語言的支援
首先在Resource中增加一個Strings檔案,
以Xcode4.4來說(New File> Resource > Strings File),
新增完成之後,在Localization中點選"Make localized..."的button,選擇要新增的語言,
在String 檔案中,輸入key及對應語言的值
在要顯示字串的地方使用
就會顯示出目前iPhone設定語言對應的String
若要拿到指定國家(以繁體中文為例)的字串則使用
以Xcode4.4來說(New File> Resource > Strings File),
新增完成之後,在Localization中點選"Make localized..."的button,選擇要新增的語言,
在String 檔案中,輸入key及對應語言的值
"Configuration" =
"設定"; "More"=
"更多";
在要顯示字串的地方使用
NSLocalizedString(@"Configuration",
nil
);
就會顯示出目前iPhone設定語言對應的String
若要拿到指定國家(以繁體中文為例)的字串則使用
NSBundle *bundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:
@"zh-Hant"
ofType:@"lproj"]];
先取得bundle,再使用NSLocalizedStringFromTableInBundle取得該國家的字串NSLocalizedStringFromTableInBundle(@"Configuration",
nil
, bundle, nil);
2012年3月30日
[iPhone]Core-Plot的使用
找到一個統計圖的Open Source Core-plot,
http://code.google.com/p/core-plot/
提供了折線圖、pie chart和bar chart等等...
如何在自己project中使用這個open source呢,
首先先把core-plot download下來,
1. 把Binaries >IOS內的 CorePlotHeaders 資料夾和libCorePlot-CocoaTouch.a拉近Project內,
2. 把內建的QuartzCore.framework加入peoject
3. 在Project Info裡面,Other Linker Flags內加入"-ObjC",如果是非Xcode4.2的版本則要加入"-all_load"
接下來就可以順利使用Core-Plot囉!
http://code.google.com/p/core-plot/
提供了折線圖、pie chart和bar chart等等...
如何在自己project中使用這個open source呢,
首先先把core-plot download下來,
1. 把Binaries >IOS內的 CorePlotHeaders 資料夾和libCorePlot-CocoaTouch.a拉近Project內,
2. 把內建的QuartzCore.framework加入peoject
3. 在Project Info裡面,Other Linker Flags內加入"-ObjC",如果是非Xcode4.2的版本則要加入"-all_load"
接下來就可以順利使用Core-Plot囉!
2012年3月13日
[iPhone]使用NSUserDefaults將自定義的Object存入手機
首先在自己的Object中加上
@interface YourObject : NSObject<NSCoding>
{
NSString *string_a;
NSString *string_b;
NSString *string_a;
NSString *string_b;
int int_c;
}
然後在這個Object中加上encoderWithObject:和initWithObject:兩個方法
-(void)encodeWithCoder:(NSCoder *)encoder { [encoder encodeObject:string_a forKey:@"string_a"]; [encoder encodeObject:string_b forKey:@"string_b"];
[encoder encodeInt:int_c forKey:@"int_c"];
}
-(id)initWithCoder:(NSCoder *)decoder { self.string_a = [decoder decodeObjectForKey: @"string_a"]; self.string_b = [decoder decodeObjectForKey: @"string_b"]; self.int_c = [decoder decodeObjectForKey:@"int_c"]; return self; }
存入的方法
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
YourObject *obj = [[YourObject alloc]init]; NSMutableArray *arr = [[NSMutableArray alloc]initWithObject:obj,nil]; NSData *data = [NSKeyedArchiver archivedDataWithRootObject:arr]; [defaults setObject:data forKey:@"theKey"];
讀取的方法
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSData *data = [defaults objectForKey:@"theKey"]; NSArray *arr = [NSKeyedUnarchiver unarchiveObjectWithData:data];
訂閱:
文章 (Atom)