ios字体大小适应不同屏幕

时间:2022-09-05 20:48:57

//根据button高度来设置字体大小

CGFloat dayLabelWidth = (viewWidth-10)/7-1;

cancelButton = [[UIButton alloc] initWithFrame:CGRectMake(viewWidth/2, viewHeight-dayLabelWidth*1.2, viewWidth/2, dayLabelWidth*1.2)];

cancelButton.titleLabel.font = [UIFont boldSystemFontOfSize:dayLabelWidth*0.5];

[cancelButton setTitle:@"取消" forState:UIControlStateNormal];

cancelButton.backgroundColor = [UIColor grayColor];

[cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

[cancelButton addTarget:self action:@selector(cancelSelectCurrentDate) forControlEvents:UIControlEventTouchUpInside];

[self addSubview:cancelButton fixedOn:viewName fixed:true];