问题描述
- 连接UISlider到fontSize的实现方法
- 不知道应该怎么实现连接UISlider到fontSize (IBAction)font1和(IBAction)font2。
.h
@interface ViewController : UIViewController{ IBOutlet UISlider* fontSizeSlider; IBOutlet UITextView* textView;}-(IBAction)sliderValueChanged:(UISlider*)sender;-(IBAction)font1;-(IBAction)font2;@end
.m
-(IBAction)sliderValueChanged:(UISlider*)sender{ textView.font = [UIFont fontWithName:@""??????"" size:sender.value];}-(IBAction)font1{ textView.font = [UIFont fontWithName:@""Heiti TC"" size:18];}-(IBAction)font2{ textView.font = [UIFont fontWithName:@""Marker Felt"" size:18];}-(IBAction)font1; //[UIButton]-(IBAction)font1; //[UIButton]-(IBAction)sliderValueChanged; //[UISlider]
解决方案
我理解的你是要从两种字体中选择,这样可以把字体放在一个NSString中实现,然后
.h
@interface ViewController : UIViewController{ IBOutlet UISlider* fontSizeSlider; IBOutlet UITextView* textView; NSString *currentFont;}-(IBAction)sliderValueChanged:(UISlider*)sender;-(IBAction)font1;-(IBAction)font2;@end
.m
-(void)viewDidLoad { [super viewDidLoad]; currentFont = @""Heiti TC""; //Or whatever your default font is textView.font = [UIFont fontWithName:currentFont size:sender.value];}-(IBAction)sliderValueChanged:(UISlider*)sender{ textView.font = [UIFont fontWithName:currentFont size:sender.value];}-(IBAction)font1{ currentFont = @""Heiti TC""; textView.font = [UIFont fontWithName:currentFont size:fontSizeSlider.value];}-(IBAction)font2{ currentFont = @""Marker Felt""; textView.font = [UIFont fontWithName:currentFont size:fontSizeSlider.value];}
时间: 2024-10-31 12:18:26