ios - 当我使用捏合手势放大和缩小 textview 字体大小时,UITextView 格式消失了
<p><p>我想使用捏合手势放大和缩小 <code>UITextView</code> 字体大小。<br/>
我正在 <code>UITextView</code> 上应用粗体、斜体、下划线等样式。<br/>
但是当我放大和缩小时,格式就消失了。<br/>
我该如何解决这个问题?</p>
<p>我正在使用以下代码:</p>
<pre><code>- (void)handleTextFieldFontOnAddMusicVc:(UIPinchGestureRecognizer *)pinchGestRecognizer{
if (pinchGestRecognizer.state == UIGestureRecognizerStateEnded
|| pinchGestRecognizer.state == UIGestureRecognizerStateChanged) {
CGFloat currentFontSize = self.myTextField.font.pointSize;
CGFloat newScale = currentFontSize * pinchGestRecognizer.scale;
if (newScale < 20.0) {
newScale = 20.0;
}
if (newScale > 60.0) {
newScale = 60.0;
}
self.myTextField.font = ;
pinchGestRecognizer.scale = 1;
}
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p><strong> Objective-C </strong> </p>
<pre><code>#import "ViewController.h"
@interface ViewController ()<UIGestureRecognizerDelegate>
{
UITextView * txtV;
UIPinchGestureRecognizer *pinchGestureRecognizer;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
;
txtV=[initWithFrame:CGRectMake(20, 50, 280, 300)];
txtV.text = @"Jai Maharashtra";
txtV.userInteractionEnabled=YES;
txtV.font= ];
;
pinchGestureRecognizer = [ initWithTarget:self action:@selector(pinchGesture:)];
pinchGestureRecognizer.delegate=self;
;
}
- (void)pinchGesture:(UIPinchGestureRecognizer *)gestureRecognizer
{
NSLog(@"*** Pinch: Scale: %f Velocity: %f", gestureRecognizer.scale, gestureRecognizer.velocity);
UIFont *font = txtV.font;
CGFloat pointSize = font.pointSize;
NSString *fontName = font.fontName;
pointSize = ((gestureRecognizer.velocity > 0) ? 1 : -1) * 1 + pointSize;
if (pointSize < 13) pointSize = 13;
if (pointSize > 42) pointSize = 42;
txtV.font = ;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 当我使用捏合手势放大和缩小 textview 字体大小时,UITextView 格式消失了,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/35860663/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/35860663/
</a>
</p>
页:
[1]