我需要根据UITextView
的值更改UISlider
的字体大小。
写于viewDidLoad()
tvVarse.text=strTextToShow; //tvVarse is the UITextViewOutlet, strTextToShow is the text to be shown on textView
经过:
UITextView
和UISlider
的插座均已连接。UITextVIew
行为“可选择”在插座中检查。UISlider
最小值为13,最大值为25英寸
出口。编辑:
UIView
我试过以下代码:
尝试1:
- (IBAction)sliderTap:(UISlider*)sender //Value changed action for UISlider
{
tvVarse.font = [tvVarse.font fontWithSize:sender.value];
}
尝试2:
- (IBAction)sliderTap:(UISlider*)sender //Value changed action for UISlider
{
dispatch_async(dispatch_get_main_queue(), ^{
tvVarse.font = [tvVarse.font fontWithSize:sender.value];
});
}
尝试3:
- (IBAction)sliderTap:(UISlider*)sender //Value changed action for UISlider
{
dispatch_async(dispatch_get_main_queue(), ^{
tvVarse.text=strTextToShow;
tvVarse.font = [tvVarse.font fontWithSize:sender.value];
[tvVarse setNeedsLayout];
[tvVarse setNeedsDisplay];
});
}
尝试4:
- (IBAction)sliderTap:(UISlider*)sender //Value changed action for UISlider
{
dispatch_async(dispatch_get_main_queue(), ^{
tvVarse.font = [tvVarse.font fontWithSize:sender.value];
tvVarse.text=strTextToShow;
[tvVarse setNeedsLayout];
[tvVarse setNeedsDisplay];
});
}
尝试5:
- (IBAction)sliderTap:(UISlider*)sender //Value changed action for UISlider
{
tvVarse.font = [tvVarse.font fontWithSize:sender.value];
tvVarse.text=strTextToShow;
}
现在有趣的一点是,当我提供其他文字时,它正在工作,即
工作但不同的小文字:
- (IBAction)sliderTap:(UISlider*)sender //Value changed action for UISlider
{
tvVarse.text=@"My name is Manab";
tvVarse.font = [tvVarse.font fontWithSize:sender.value];
}
任何人都可以告诉我为什么这些不起作用?
答案 0 :(得分:1)
试试这个......
首先设置字体然后再写文字......
tvVarse.font = [tvVarse.font fontWithSize:sender.value];
tvVarse.text=strTextToShow;
答案 1 :(得分:0)
所以我尝试过这个有趣的伎俩(很棒,它正在发挥作用):
- (IBAction)sliderTap:(UISlider*)sender
{
tvVarse.text=@"";//Just provided blank text before loading textview again
tvVarse.font = [tvVarse.font fontWithSize:sender.value];
tvVarse.text=strTextToShow;
}
但我不知道它为什么会起作用!!