您的位置:首页 > 产品设计 > UI/UE

【代码笔记】关于UIFont的一些define

2016-03-15 10:00 579 查看
一,效果图。





二,工程图。





三,代码。

RootViewController.h

#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController

@end


RootViewController.m

#import "RootViewController.h"
#import "Utils.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

//初始化背景图
[self addView];

//初始化button
[self initButton];

}
#pragma -mark -functions
//初始化背景图
-(void)addView
{
self.title=@"UIFont";
}
//初始化button
-(void)initButton
{
UIButton *rightButton = [[UIButton alloc] initWithFrame:CGRectMake(50, 100, 100, 50)];
[rightButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
rightButton.backgroundColor=[UIColor redColor];
//给按钮上的字设置大小
[Utils setDefaultFont:rightButton size:20];
[rightButton setTitle:@"完成" forState:UIControlStateNormal];
[self.view addSubview:rightButton];

}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}


Utils.h

#import <Foundation/Foundation.h>

@interface Utils : NSObject

+ (void)setDefaultFont:(id)sender size:(float)size;

@end


Utils.m

#import "Utils.h"

@implementation Utils

//给某个按钮上的数字设置大小
+ (void)setDefaultFont:(id)sender size:(float)size{
[sender setFont:[UIFont fontWithName:@"Helvetica" size:size]];
}

@end


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: