2 lianlianbushell lianlianbushell 于 2012.12.25 09:52 提问

连接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]

1个回答

abcdeFGh_xyz
abcdeFGh_xyz   2012.12.25 10:50
已采纳

我理解的你是要从两种字体中选择,这样可以把字体放在一个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];
}
Csdn user default icon
上传中...
上传图片
插入图片