以编程方式更改UIView的位置

西德斯·杰夫(Sidharth J Dev)

截屏

我的应用程序中有一个阿拉伯语页面,阿拉伯语页面中的“日期字段”必须与视图的右侧对齐(现在,它位于左侧)。我尝试了以下代码

    -(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
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章