2013-04-30 101 views
0

我正在使用Xcode 4.6.2並且針對iOS 6及更高版本。 我已經爲我的問題創建了示例代碼。UITextView在RTL語言中的對齊

代碼在.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 

接口設計

http://d.pr/i/oP7G

http://d.pr/i/1TM

問題是這樣的:

向TextView添加一些文本後,如果鍵盤是英文,NSTextAlignment工作得很好。 但是,如果我將鍵盤更改爲阿拉伯語並寫入任何內容,NSTextAlignment將不會響應,它不會更改對齊方式。

任何想法如何解決這個問題?根據文本

回答

0

使用文本框代表

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string 

,並設置對齊進入

文本字段調用此方法每當用戶在文本字段中一個新的字符或刪除現有字符。在這裏你可以用一個新的NSString替換你的輸入,你從右向左放置字符。

還設置

textView.textAlignment = UITextAlignmentRight; 

將您提示右側。

0

選擇UITextView,然後轉到對齊部分中的屬性檢查器選擇第四個(等於)對齊