我的应用程序中有一个阿拉伯语页面,阿拉伯语页面中的“日期字段”必须与视图的右侧对齐(现在,它位于左侧)。我尝试了以下代码
-(void)changeDatePosition{
if (!_isEnglish) {
CGRect currentDatePostion=_viewForDate.frame;
[_viewForDate removeFromSuperview];
currentDatePostion.origin.x+=currentDatePostion.size.width;
_viewForDate.frame=currentDatePostion;
[_baseView addSubview:_viewForDate];
}
}
但这没有帮助。该视图将自身定位在导航栏的顶部(x坐标也不变)。我已经使用自动布局将“ViewForDate”(日期字段)的左前导空格与“PlacesView”(日期字段顶部的视图)的前导空格对齐。但我将其优先级设置为250。如何解决此问题?
最佳答案
将IBOutlet挂钩到日期视图的前导约束,并将其值设置为0。然后尝试以下代码:
-(void)changeDatePosition{
if (!_isEnglish) {
_dateViewLeadConstraint.constant = x;
}
//x - amount by which view should move right, you can calculate based on your view setup
}
关于ios - 以编程方式更改UIView的位置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32688123/