[英]Change UITableView direction to Right-to-Left
I develop an iOS application and my native language is Persian (a Right-to-Left language). 我开发了一个iOS应用程序,我的母语是波斯语(一种从右到左的语言)。 How can I change UITableView direction to right-to-left in iOS programming?
如何在iOS编程中将UITableView方向更改为从右到左?
A UITableView with RTL direction has: 具有RTL方向的UITableView具有:
like this : 像这样 :
Is there any UI or programming way to do this? 是否有任何UI或编程方式来执行此操作?
我知道它会自iOS8以来自动改为从右到左。
You can try to do this as well 您也可以尝试这样做
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = myTableView.dequeueReusableCellWithIdentifier("cell")! as UITableViewCell
cell.textLabel?.textAlignment = .Right
cell.textLabel?.text = goalsArray[indexPath.row]
return cell
}
Build your view's constraints with NSLayoutAttributeLeading
and NSLayoutAttributeTrailing
instead of NSLayoutAttributeLeft
and NSLayoutAttributeRight
. 使用
NSLayoutAttributeLeading
和NSLayoutAttributeTrailing
而不是NSLayoutAttributeLeft
和NSLayoutAttributeRight
构建视图的约束。
Your view's Direction will be the same with your app's language Direction. 您的视图的方向将与您应用的语言方向相同。
for me this way worked 对我来说这种方式很有效
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier)! as UITableViewCell
//cell.myView.backgroundColor = self.colors[indexPath.row]
cell.textLabel?.text =
"\((self.FAQs?[indexPath.row].Question)!)"
cell.textLabel?.textAlignment = .right
return cell
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.