你的位置:首页 > 操作系统

[操作系统]【代码笔记】关于UIFont的一些define


一,效果图。

二,工程图。

三,代码。

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
复制代码