Translate
2013年5月8日 星期三
2013年5月7日 星期二
ios-tips-custom-fonts
參考link
首先先把.ttf檔放進專案裡
確定有勾選Add to targets
Verify the font is in the project. There are two places you can do this.
By selecting the font, and verifying “Target Membership” in the Utilities area.
And By selecting your apps target, selecting the “Build Phases” tab, and verifying that your font is in the “Copy Bundle Resources” section.
And finally, add the font to your Info.plist. Note that most apps change the name of their plist to something like-Info.plist. Add a key of “Fonts provided by application”, and make sure it’s an array, then add your font file name as an item in the array. Make sure you use the exact file name, and that your file name has an all-lowercase extension (.TTF apparently doesn’t work on iPhones, but .ttf does).
Knowing your font
This is where I had some issues. When you add your font you use the file name, but when you use your font you use the font name… The EXACT font name. If you ctrl + click on the .ttf file and select “Get Info”, you can find the “Full Name”. That seems to work with a lot of fonts, but the font I’m using doesn’t work that way. I had to open the .ttf file in the Font Book application, and look at the window header.
Using this name, you can log what font names you have available by using the fontNamesForFamilyName method like so:
Using your font programmatically
Say you have a UILabel:
UILabel *myLabel = [[UILabel alloc] init];
[myLabel setText:@"Label Text"];
We set the font of our label by creating a UIFont, and setting it to our label with setFont.
首先先把.ttf檔放進專案裡
確定有勾選Add to targets
Verify the font is in the project. There are two places you can do this.
By selecting the font, and verifying “Target Membership” in the Utilities area.
And By selecting your apps target, selecting the “Build Phases” tab, and verifying that your font is in the “Copy Bundle Resources” section.
And finally, add the font to your Info.plist. Note that most apps change the name of their plist to something like
Knowing your font
This is where I had some issues. When you add your font you use the file name, but when you use your font you use the font name… The EXACT font name. If you ctrl + click on the .ttf file and select “Get Info”, you can find the “Full Name”. That seems to work with a lot of fonts, but the font I’m using doesn’t work that way. I had to open the .ttf file in the Font Book application, and look at the window header.
Using this name, you can log what font names you have available by using the fontNamesForFamilyName method like so:
NSLog(@"tt0001m_: %@",
[UIFont fontNamesForFamilyName:@"Swis721 Lt BT"]
);
Which gives the output:
2012-08-24 11:25:10.968 GenericKeychain[7260:c07] tt0001m_: (
"Swiss721BT-Light"
)
Using your font programmatically
Say you have a UILabel:
UILabel *myLabel = [[UILabel alloc] init];
[myLabel setText:@"Label Text"];
We set the font of our label by creating a UIFont, and setting it to our label with setFont.
UIFont *swissLight = [UIFont
fontWithName:@"Swiss721BT-Light"
size:myLabel.font.pointSize];
[myLabel setFont:swissLight];
2013年5月3日 星期五
GCD全称为Grand Central Dispatch dispatch_async
ios-ALAssetsLibrary获取系统相簿里边的所有照片
參考link
-(void)getImgs{
dispatch_async(dispatch_get_main_queue(), ^{
NSAutoreleasePool *pool = [[NSAutoreleasePoolalloc] init];
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror){
NSLog(@"相册访问失败 =%@", [myerrorlocalizedDescription]);
if ([myerror.localizedDescription rangeOfString:@"Global denied access"].location!=NSNotFound) {
NSLog(@"无法访问相册.请在'设置->定位服务'设置为打开状态.");
}else{
NSLog(@"相册访问失败.");
}
};
ALAssetsGroupEnumerationResultsBlock groupEnumerAtion = ^(ALAsset *result,NSUInteger index, BOOL *stop){
if (result!=NULL) {
if ([[result valueForProperty:ALAssetPropertyType]isEqualToString:ALAssetTypePhoto]) {
NSString *urlstr=[NSString stringWithFormat:@"%@",result.defaultRepresentation.url];//图片的url
/*result.defaultRepresentation.fullScreenImage//图片的大图
result.thumbnail //图片的缩略图小图
// NSRange range1=[urlstr rangeOfString:@"id="];
// NSString *resultName=[urlstr substringFromIndex:range1.location+3];
// resultName=[resultName stringByReplacingOccurrencesOfString:@"&ext=" withString:@"."];//格式demo:123456.png
*/
[self._dataArray addObject:urlstr];
}
}
};
ALAssetsLibraryGroupsEnumerationResultsBlock
libraryGroupsEnumeration = ^(ALAssetsGroup* group,BOOL* stop){
if (group == nil)
{
}
if (group!=nil) {
NSString *g=[NSString stringWithFormat:@"%@",group];//获取相簿的组
NSLog(@"gg:%@",g);//gg:ALAssetsGroup - Name:Camera Roll, Type:Saved Photos, Assets count:71
NSString *g1=[g substringFromIndex:16 ] ;
NSArray *arr=[NSArray arrayWithArray:[g1componentsSeparatedByString:@","]];
NSString *g2=[[arr objectAtIndex:0]substringFromIndex:5];
if ([g2 isEqualToString:@"Camera Roll"]) {
g2=@"相机胶卷";
}
NSString *groupName=g2;//组的name
[groupenumerateAssetsUsingBlock:groupEnumerAtion];
}
};
ALAssetsLibrary* library = [[ALAssetsLibraryalloc] init];
[libraryenumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:libraryGroupsEnumeration
failureBlock:failureblock];
[library release];
[pool release];
});
}
//------------------------根据图片的url反取图片-----
ALAssetsLibrary *assetLibrary=[[ALAssetsLibraryalloc] init];
NSURL *url=[NSURLURLWithString:urlStr];
[assetLibrary assetForURL:url resultBlock:^(ALAsset *asset) {
UIImage *image=[UIImage imageWithCGImage:asset.thumbnail];
cellImageView.image=image;
}failureBlock:^(NSError *error) {
NSLog(@"error=%@",error);
}
];
訂閱:
文章 (Atom)