gpt4 book ai didi

iphone - 将 UISlider 连接到 fontSize

转载 作者:行者123 更新时间:2023-11-28 22:42:47 25 4
gpt4 key购买 nike

将 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com