iOS 7中UI元素的对齐问题
我已经用代码编写了一个UITableView单元格iOS 7中UI元素的对齐问题,ios,iphone,swift,uitableview,xcode6,Ios,Iphone,Swift,Uitableview,Xcode6,我已经用代码编写了一个UITableView单元格 override init(style: UITableViewCellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) var yPos : CGFloat = 10.0 let collectionFrame = CGRectMake(0, yPos, Consta
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单元格中的所有UIElemen都已向左移动。即使对于X位置为零的UIElement(UIElement的某些部分从屏幕左侧移出),这种情况仅在iOS 7中发生。我正在使用的应用程序支持从iOS 7到iOS 8.3,它是一个通用应用程序。也许您必须检查单元格及其内容的自动调整大小值 1) 转到故事板 2) 选择单元格 3) 转到“尺寸检查器”选项卡
4) 尝试修改其内容的自动调整大小值是否使用序列图像板或xib文件?我在该序列图像板中使用序列图像板我使用的是用codeHi编写的自定义tableViewCell,事实上,我已经用代码编写了tableViewCell,但是tableView在故事板中。如何将您的解决方案应用于用代码编写的tableViewCell。你知道还有什么其他解决方案可以解决我的问题吗?你可以“玩”tableView中每个元素的autoresizingMask。您还必须检查此处的文档: