我正在使用 Xcode 4.6.2 并针对 iOS 6 及更高版本。我为我的问题创建了示例代码。
.h 文件中的代码
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UITextViewDelegate>
@property (strong, nonatomic) IBOutlet UITextView *myTextView;
- (IBAction)btnLeftAlignment:(id)sender;
- (IBAction)btnCenterAlignment:(id)sender;
- (IBAction)btnRightAlignment:(id)sender;
- (IBAction)btnJustifiedAlignment:(id)sender;
@end
.m 文件中的代码
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize myTextView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.myTextView.delegate = self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)btnLeftAlignment:(id)sender
{
myTextView.textAlignment = NSTextAlignmentLeft;
}
- (IBAction)btnCenterAlignment:(id)sender
{
myTextView.textAlignment = NSTextAlignmentCenter;
}
- (IBAction)btnRightAlignment:(id)sender
{
myTextView.textAlignment = NSTextAlignmentRight;
}
- (IBAction)btnJustifiedAlignment:(id)sender
{
myTextView.textAlignment = NSTextAlignmentJustified;
}
@end
界面设计
问题是这样的:
在向 TextView 添加一些文本后,如果键盘是英文的,则 NSTextAlignment 工作得很好。但是,如果我将键盘更改为阿拉伯语并写任何 NSTextAlignment 不会响应的内容,它也不会更改对齐方式。
知道如何解决这个问题吗?