将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];
}
关于iphone - 将UISlider连接到fontSize,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14026512/