通过UITextView中的UiBarButtonItem更改字体大小,仅工作一次 [英] Change font size via UiBarButtonItem in UITextView, works just once
本文介绍了通过UITextView中的UiBarButtonItem更改字体大小,仅工作一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有UiTextView,我想在其中更改字体大小(增加),此处为代码
I have UiTextView where I want change font size (increase), here code
-(void)biggerFont:(UIBarButtonItem *) item {
CGFloat i = [UIFont systemFontSize];
textView.font = [UIFont fontWithName:@"Tahome" size:i];
i+=2;
}
但是它只工作一次,如果您再按一次又一次-fon大小不会改变.请帮助我
But it works just once, if you push once and after that again - fon size won't change. Help me please
推荐答案
很容易,您无需持久保存i的状态.每当您将i设置为相同的值时.方法执行完后,i将被丢弃,因为它仅存在于方法范围内.
It's easy you are not saving the state of i persistently. Everytime you set i to the same value. After the method has been run through i is discarded cause it only exists in the methods scope.
将i更改为类似的属性
CGFloat myFontSize;
@property(nonatomic) CGFloat myFontSize;
例如,在viewWillLoad中设置默认值
For example in the viewWillLoad you set the default value
self.myFontSize = [UIFont systemFontSize];
您的方法更改为
-(void)biggerFont:(UIBarButtonItem *) item
{
myFontSize += 2;
textView.font = [UIFont fontWithName:@"Tahome" size:myFontSize];
}
这篇关于通过UITextView中的UiBarButtonItem更改字体大小,仅工作一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文