Translate

顯示具有 Custom 標籤的文章。 顯示所有文章
顯示具有 Custom 標籤的文章。 顯示所有文章

2013年5月8日 星期三

UIButton custom font vertical alignment

我在專案裡面用了客制化的字體
發現我的UIButton的字不在正中間


上網查到許多方法
參考link
參考link
參考link

最後我使用了最簡單的方法
yourButton.contentEdgeInsets = UIEdgeInsetsMake(5, 0, 0, 0);

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:

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年4月16日 星期二

Custom Fonts

參考網站

在專案裡面需要用到ttf的字型
所以記錄一下

加入the .ttf檔案到專案裡



確定Add to targets是勾起來的



點選.ttf檔確定右手邊的Target Memvership是打勾的



在回專案的TARGETS->Build Phases->Copy Bundle Resources



最後在專案的info.plist增加Fonts provided by application並加上.ttf的檔案名稱



然後取得.ttf的全名



使用方法
NSLog(@"vagrounded-bold.ttf is %@", [UIFont fontNamesForFamilyName:@"VAGRounded-Bold"] ); NSLog(@"vagrounded-thin.ttf is %@", [UIFont fontNamesForFamilyName:@"VAGROUNDED-Thin"] ); UILabel *lab = [UILabel new]; [lab setFrame:CGRectMake(50, 50, 100, 30)]; UIFont *swissLight = [UIFont fontWithName:@"VAGRounded-Bold" size:20.0f]; [lab setFont:swissLight]; [lab setText:@"GodCam"]; [self.view addSubview:lab]; UILabel *lab2 = [UILabel new]; [lab2 setFrame:CGRectMake(50, 100, 100, 30)]; UIFont *swissLight2 = [UIFont fontWithName:@"VAGROUNDED-Thin" size:20.0f]; [lab2 setFont:swissLight2]; [lab2 setText:@"GodCam"]; [self.view addSubview:lab2]; 2013-04-17 13:48:20.635 UseTTF[787:c07] vagrounded-bold.ttf is ( "VAGRounded-Bold" ) 2013-04-17 13:48:20.636 UseTTF[787:c07] vagrounded-thin.ttf is ( "VAGROUNDED-Thin" )

2013年3月26日 星期二

Custom UITableViewCell setSelectedBackgroundView

在專案又用到客制化的select時的特效改變
上網查了一下原來不難
最簡單的方法為
cell.selectionStyle = UITableViewCellSelectionStyleGray;

但是這跟我要的顏色不同
所以呢又發現到有這樣的寫法
UIView *bgColorView = [[UIView alloc] init]; [bgColorView setBackgroundColor:[UIColor redColor]]; [cell setSelectedBackgroundView:bgColorView];
如果你的Custom UITableViewCell 使用在groupe樣板
Don't forget to import QuartzCore.
UIView *bgColorView = [[UIView alloc] init]; [bgColorView setBackgroundColor:[UIColor redColor]]; bgColorView.layer.cornerRadius = 10; [cell setSelectedBackgroundView:bgColorView]; [bgColorView release];
另外一種是我沒試過的
在Custom UITableViewCell的.m檔裡作修改
- (void)setSelected:(BOOL)selected animated:(BOOL)animated { UIImage *selectionBackground = [UIImage imageNamed:@"yellow_bar.png"]; UIImageView *iview=[[UIImageView alloc] initWithImage:selectionBackground]; self.selectedBackgroundView=iview; }