不知道應該怎麼實現連接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];
}