1.- (void)viewDidLoad先设置字体的全局变量
font=14;
2. 自定义2个按钮并添加事件
//放大
_zoomInBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_zoomInBtn.frame = CGRectMake(185, 7 , 30, 30);
_zoomInBtn.backgroundColor = [UIColor clearColor];
[_zoomInBtn setImage:[UIImage imageNamed:@"ButtonZoomIn.png"] forState:UIControlStateNormal];
_zoomInBtn.tag = 220;
[_zoomInBtn addTarget:self action:@selector(fontSizeAdjustment:) forControlEvents:UIControlEventTouchUpInside];
[engLishSetView addSubview:_zoomInBtn];
//缩小
_zoomOutBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_zoomOutBtn.frame = CGRectMake(265, 7 , 30, 30);
_zoomOutBtn.backgroundColor = [UIColor clearColor];
_zoomOutBtn.tag = 221;
[_zoomOutBtn addTarget:self action:@selector(fontSizeAdjustment:) forControlEvents:UIControlEventTouchUpInside];
[_zoomOutBtn setImage:[UIImage imageNamed:@"ButtonZoomOut.png"] forState:UIControlStateNormal];
[engLishSetView addSubview:_zoomOutBtn];
3.实现方法
#pragma mark - 字体调整大小事件
-(void)fontSizeAdjustment:(id)sender
{
NSLog(@"%f",font);
UIButton * btn = (UIButton *)sender;
if (btn == _zoomInBtn) {
if (font<20) {
font = font+1;
[_zoomOutBtn setEnabled:YES];
[_englishDetailTable reloadData];
}
else
{
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:nil message:@"字体已经为最大" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
[alert show];
[_zoomInBtn setEnabled:NO];
}
}
else
{
if (font>12) {
font = font-1;
[_zoomInBtn setEnabled:YES];
[_englishDetailTable reloadData];
}
else
{
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:nil message:@"字体已经为最小" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
[alert show];
[_zoomOutBtn setEnabled:NO];
}
}
}