Tag: 布局

如何显示每行3个单元的UICollectionView

根据标题,我使用UICollectionView来显示图像。 我需要每行显示3个单元格,就像Instagram做的那样。 因为有很多屏幕尺寸,我得到iPhone屏幕的宽度,然后除以3。但是,它不显示为我所需要的。 这里是我的代码里面的viewDidLoad()方法: private let leftAndRightPaddings: CGFloat = 8.0 private let numberOfItemsPerRow: CGFloat = 3.0 private let heightAdjustment: CGFloat = 30.0 let bounds = UIScreen.mainScreen().bounds let width = (bounds.size.width – leftAndRightPaddings) / numberOfItemsPerRow let layout = userDetailCollection.collectionViewLayout as! UICollectionViewFlowLayout layout.itemSize = CGSizeMake(width, width)

XCode 7 Autolayout约束条件:如何使2张图片在中间保持水平

我试图将2个UIImage视图并排放置在屏幕中央。 如果它只是1 UIImage,我可以将它们设置为在容器中垂直和水平居中。 如果我有2个UIImage视图并排,我只能将它设置为垂直居中,但不是水平居中,因为两个UIImage视图将堆叠在一起。 有人能指导我吗? 谢谢,非常感谢!

AutoLayout不使用Storyboard或Interface Builder

我正在构build一个应用程序,我希望完全避免使用Storyboard和Interface Builder,因此应该在代码中指定所有UI。 我正在使用PureLayout ,一个很好的API来configurationAutoLayout约束。 但是,我的问题是,似乎像AutoLayout不使用Interface Builder时被禁用。 updateViewConstraints ,根据PureLayout作者给出的build议放置布局的方法根本不被调用。 只是为了提供更多有关我的设置的信息: 删除Main.storyboard并从Info.plist删除条目 在AppDelegate.m手动设置self.window并添加MainMainController UINavigationController作为rootViewController 如上所述,我的主要问题是, updateViewConstraints不会在MainViewController调用,但UI元素都显示与我在初始化过程中传递给他们的frame 。 注意 :在我看来,我只是需要在某处启用某个标志来模仿Interface Builder中的checkbox,您可以使用它来指示是否要使用AutoLayout 。 MainViewController.m @interface MainViewController () @property (nonatomic, strong) UIButton *startButton; @property (nonatomic, assign) BOOL didSetupConstraints; @end @implementation MainViewController – (void)viewDidLoad { [super viewDidLoad]; [self.view addSubview:self.startButton]; [self.view setTranslatesAutoresizingMaskIntoConstraints:NO]; } – (UIButton *)startButton { if (!_startButton) { UIButton *startButton […]

我希望两个button具有相同的宽度,并使用自动布局按比例放置在屏幕顶部的所有屏幕尺寸中。

附加我打算devise的视图。 我想定位的button相对于超视图和他们的宽度和高度必须成比例增加屏幕尺寸,而不是保持不变。 附加屏幕预览:

如何将对象放置在中心图像周围的数组中?

我有一个buttonarrays,当我把它们追加到一个视图,我想要定位在中心的图像视图。 根据arrays中有多less物体,我希望它们在整个圆周上均匀分布。 以下是我的尝试。 我做错了什么,我该如何解决? 驼鹿后面有不止一个button。 var userbutton = [UIButton]() var upimage = [UIImage]() var locationpic = [AnyObject]() func locationsSet(){ for (index, users) in upimage.enumerate() { let userbutton = UIButton() userbutton.addTarget(self, action: "buttonAction:", forControlEvents: .TouchUpInside) userbutton.frame = CGRectMake(100, 100, 50, 50) userbutton.layer.cornerRadius = userbutton.frame.size.width/2 userbutton.clipsToBounds = true userbutton.setImage(users, forState: .Normal) let radians = CGFloat(M_PI) * 2.0 […]

自动布局以编程方式修改约束乘数

如何以编程方式修改约束的乘数? 我已经设置了以下内容: [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_button attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:0.5 constant:0.0]]; 我需要修改它到这个: [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_button attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0.0]];

如果我使用圆形图像,ImageView中不显示图像

我有一个表视图,我需要在部分标题中显示author_img。 在ViewForSectionHeader方法中,我想使图像成为圆形。 但是如果我这样做,不pipe是在模拟器还是在真实的设备上,图像都不会显示出来。 如果我删除代码,uiimageview将正常显示图像。 我为uiimageview设置了宽度和高度约束,因为我想获得固定大小的显示图像。 那么有什么想法吗? cell.author_img.layer.cornerRadius = cell.author_img.frame.size.width/2 cell.author_img.layer.masksToBounds = true // add a boundary for thumb cell.author_img.layer.borderWidth = 1.5 cell.author_img.layer.borderColor = UIColor.whiteColor().CGColor

如何在Interface Builder中使用自动布局创build键盘附件视图?

我想添加一个“完成”button和分段控制到十进制键盘。 理想情况下,我想在界面生成器中使用自动布局布局键盘附件视图。 这甚至有可能吗? 我是否创build一个新的XIB,或者我可以在现有的Storyboard场景中做些什么? 如何将附件视图附加到适当的文本字段?

Main.Storyboard框架未更新

我目前正在制作一个我打算提交给iOS App Store的应用程序。 通常情况下,当我在Xcode的Main.Storyboard中更新我的框架时,它就像这样。 但是,现在没有。 每当我closures应用程序并稍后重新打开,帧都不会更新。 它看起来像这样: 我更新了框架后,它看起来像这样(我想它看起来像): 当我在模拟器上运行应用程序仍然看起来不错,但我的应用程序仍然有16个警告。 我想删除这些错误(我之前提到)我正在提交这个应用程序到iOS应用程序商店。 我怎样才能解决这个问题? 谢谢。

防止界面生成器自动创build约束?

我在这里创build了一个演示项目。 我有一个视图,我在.xib文件中创build了一个ScrollView。 在界面生成器中,我没有设置任何约束。 在我的viewDidLoad方法中,我使用SnapKit设置约束: scrollView.snp_makeConstraints { (make) -> Void in make.edges.equalTo(self.view) } 当我运行代码时,我得到以下控制台输出: Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that […]