繁体   English   中英

iOS 7中UIElements的对齐问题

[英]Alignment issue of UIElements in iOS 7

我已经在代码中编写了一个UITableView单元格。

override init(style: UITableViewCellStyle, reuseIdentifier: String?) 
{

super.init(style: style, reuseIdentifier: reuseIdentifier)

        var yPos : CGFloat = 10.0

        let collectionFrame = CGRectMake(0, yPos, Constants.DimentionKeys.kDeviceWidth, Constants.DimentionKeys.kDeviceWidth)
        var layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
        layout.scrollDirection = UICollectionViewScrollDirection.Horizontal
        layout.itemSize = CGSizeMake(Constants.DimentionKeys.kDeviceWidth, Constants.DimentionKeys.kDeviceWidth)
        layout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
        layout.minimumInteritemSpacing = 0
        layout.minimumLineSpacing = 0

        self.ImageCollectionView = UICollectionView(frame: collectionFrame, collectionViewLayout: layout)
        self.ImageCollectionView!.registerClass(CollectionViewCell.self, forCellWithReuseIdentifier: "CollectionViewCell")
        self.ImageCollectionView?.tag = 11
        self.ImageCollectionView?.pagingEnabled = true
        self.ImageCollectionView?.backgroundColor = UIColor(red: 242/255.0, green: 237/255.0, blue: 235/255.0, alpha: 1.0)

        self.contentView.addSubview(self.ImageCollectionView!)



        self.ShareBtn.frame = CGRectMake(10.0, yPos, 35.0, 35.0)
        self.ShareBtn.setImage(UIImage(named: "share"), forState: UIControlState.Normal)
        self.contentView.addSubview(self.ShareBtn)

        yPos += collectionFrame.height

        self.offerLbl.frame = CGRectMake(10.0, yPos, Constants.DimentionKeys.kDeviceWidth - 20.0, 30.0)
        self.offerLbl.numberOfLines = 3
        self.offerLbl.textAlignment = NSTextAlignment.Center
        self.offerLbl.font = UIFont(name: "Helvetica Neue", size: 12.0)
        self.offerLbl.backgroundColor = UIColor(red: 213/255.0, green: 221/255.0, blue: 234/255.0, alpha: 1.0)
        self.contentView.addSubview(self.offerLbl)

        yPos += 45.0

        self.priceLbl.frame = CGRectMake(10.0, yPos, self.offerLbl.frame.size.width - 35.0, 35.0)
        self.priceLbl.font = UIFont(name: "Verdana", size: 21.0)
        self.contentView.addSubview(self.priceLbl)

        self.wishListBtn.frame = CGRectMake(self.priceLbl.frame.size.width + 10.0, yPos, 35.0, 35.0)
        self.wishListBtn.setImage(UIImage(named: "wishlist"), forState: UIControlState.Normal)
        self.contentView.addSubview(self.wishListBtn)

        yPos += 40.0

        self.splPriceLbl.frame = CGRectMake(10.0, yPos, self.priceLbl.frame.width, 20.0)
        self.splPriceLbl.font = UIFont(name: "Verdana", size: 14.0)
        self.splPriceLbl.textColor = UIColor.redColor()
        self.contentView.addSubview(self.splPriceLbl)

        yPos += 25.0


        self.productNameLbl.frame = CGRectMake(10.0, yPos, self.frame.width - 20.0, 20.0)
        self.productNameLbl.font = UIFont(name: "Helvetica Neue", size: 16.0)
        self.contentView.addSubview(self.productNameLbl)

        yPos += 22.0

        self.productDescLbl.frame = CGRectMake(10.0, yPos, self.frame.width - 20.0, 40.0)
        self.productDescLbl.font = UIFont(name: "Helvetica Neue", size: 13.0)
        self.productDescLbl.numberOfLines = 5
        self.contentView.addSubview(self.productDescLbl)

        yPos += 45.0


        self.variantSelectorBtn.frame = CGRectMake(10.0, yPos, (Constants.DimentionKeys.kDeviceWidth / 2.0 - 20.0 ), 35.0)
        self.variantSelectorBtn.setTitle("Customise this product", forState: UIControlState.Normal)
        self.variantSelectorBtn.titleLabel?.font = UIFont.systemFontOfSize(12.0)
        self.variantSelectorBtn.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        self.variantSelectorBtn.layer.borderWidth = 1.0
        self.variantSelectorBtn.layer.borderColor = UIColor.blackColor().CGColor
        self.contentView.addSubview(self.variantSelectorBtn)


        self.TBtn.frame = CGRectMake(Constants.DimentionKeys.kDeviceWidth / 2.0 + 20.0, yPos, Constants.DimentionKeys.kDeviceWidth / 2.0 - 40.0, 35.0)
        self.TBtn.setAttributedTitle(Product.getTwoColorString("Free Try"), forState: UIControlState.Normal)
        self.TBtn.titleLabel?.font = UIFont.systemFontOfSize(12.0)
        self.TBtn.layer.borderWidth = 1.0
        self.TBtn.layer.borderColor = UIColor.blackColor().CGColor
        self.contentView.addSubview(self.TBtn)

        yPos += 35.0

    }

该UITableView单元中的所有UIElemens在执行时都向左移动。 即使对于X位置为零的UIElement(该UIElement的某些部分从屏幕移到左侧)也仅在iOS 7中发生。 我正在使用的应用程序支持从iOS 7到iOS 8.3,它是一个通用应用程序。

也许您必须检查单元格及其内容的自动调整大小值。

1)转到情节提要。

2)选择单元格

3)转到尺寸检查器选项卡

4)尝试修改其内容的自动调整大小值

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM