Tag: uiedgeinsets

使用UIEdgeInsets布局UIButton

您可以使用插图来布局系统或自定义按钮的内容。 通过插入,您可以为按钮的标题( titleEdgeInsets ),图像( imageEdgeInsets )以及标题和图像( contentEdgeInsets )一起添加或删除空间。 要查看这三个属性的工作原理,请通过xib文件或创建一个按钮( UIButton ) 在代码中。 在超级视图约束中,仅在垂直和水平方向上给它一个中心,在第一个示例中,不给它一个宽度上的约束。 为contentView提供蓝色背景色,为imageView提供红色背景色,为titleLabel提供黄色背景色。 最重要的是,您还可以为按钮的边框赋予绿色。 button.backgroundColor = .blue button.imageView?.backgroundColor = .red button.titleLabel?.backgroundColor = .yellow button.layer.borderColor = UIColor.green.cgColor button.layer.borderWidth = 2 contentEdgeInsets的行为符合您的预期。 您可以使用正值在imageView和titleLabel周围添加空间。 让间距:CGFloat = 8.0 button.contentEdgeInsets = UIEdgeInsets(顶部:0,左侧: 间距 ,底部:0,右侧: 间距 ) 当涉及titleEdgeInsets或imageEdgeInsets时,规则是向左右插图添加相等和相反的偏移量。 因此,例如,如果在左侧标题插图上添加8点,则需要在右侧插图上加上-8点。 这样,您仅使用插图来偏移标题或图像,而不以任何方式调整它们的大小。 如果不执行此操作,则计算的布局矩形可能会变得太小,标题可能会被截断,并且间距将显示一些奇怪的行为。 button.titleEdgeInsets = UIEdgeInsets(top:0,left:interval,bottom:0,right: 0 ) 要翻转带有图像的标题,我们可以使用imageEdgeInsets和titleEdgeInsets将imageView移动到titleLabel后面。 首先,我们将imageView的大小与按钮宽度向右移动,然后减去该图像的宽度,以使imageView保留在内容视图中。 它看起来像这样: 我们为右插图设置左插图的相反值: […]

UILabel上的文本填充

在这里,我正在尝试在文本周围添加一些填充(左,右,上,下)的标签。 这个问题在SOF上有相关的post,在阅读了其中的一些之后,我试着使用这里提出的一个解决scheme: 这是我的子类UILabel的代码: import UIKit class LuxLabel: UILabel { //let padding: UIEdgeInsets var padding: UIEdgeInsets = UIEdgeInsets.zero { didSet { self.invalidateIntrinsicContentSize() } } // Create a new PaddingLabel instance programamtically with the desired insets required init(padding: UIEdgeInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)) { self.padding = padding super.init(frame: CGRect.zero) } // Create […]

如何在iphone中使用Button中的UIEdgeInsets属性

我是iOS应用程序开发新手,想知道如何在button中使用UIEdgeInsets属性,请指导我。

如何用imageEdgeInsets在UIButton中更改图片的tintColor?

II在我的Objective-C应用程序中有一个UIButton。 我的button被修改添加文本和图像,如: – (void)centerButtonAndImageWithSpacing:(CGFloat)spacing { CGFloat insetAmount = spacing / 2.0; self.imageEdgeInsets = UIEdgeInsetsMake(0, -insetAmount, 0, insetAmount); self.titleEdgeInsets = UIEdgeInsetsMake(0, insetAmount, 0, -insetAmount); self.contentEdgeInsets = UIEdgeInsetsMake(0, insetAmount, 0, insetAmount); } 然后我添加这个代码的图像: [self.myButton setImage:[UIImage imageNamed:@"imageButton.png"] forState:UIControlStateNormal]; 我想改变图像的tintColor,但是当我尝试改变这个,我的代码是不工作的: [self.myButton setTintColor:[UIColor redColor]]; 我想使用这个代码,但没有工作: UIImage* img = [UIImage imageNamed:imageName]; icon.image = [img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; icon.tintColor = [UIColor redColor]; 我有这个: 我想得到它: […]

带有内容插入的UIScrollView自动更改边界

我使用UIScrollView作为分页滚动视图pagesScrollView 。 里面,我把个别UIScrollViews专门用于缩放。 在每个内部,我有一个视图,这是应该是可缩放的页面项目。 所有这一切都在一个带有半透明导航栏的UINavigationController中。 我pagesScrollView有contentInset.top = 64和bounds.origin.y = -64 (这似乎很奇怪,但这就是系统自动设置为我),这工作得很好。 我的屏幕看起来不错! 然而,在scrollViewWillEndDragging调用scrollViewWillEndDragging之后, scrollViewWillEndDragging会从bounds.origin.y = -64开始animation变化为bounds.origin.y = 0 ,这会导致我的页面项目被遮挡由导航栏。 左边是加载时的样子,右边是拖动几个像素后的样子,然后放开,在导航栏下滑动(因为bounds.origin.y会变成0) 。 问题是,我没有任何代码正在改变的界限,我没有任何代码在各种滚动委托方法做任何事情。 我已经添加了一堆滚动委托方法,只是添加了NSLog(),所以我可以找出更改发生的时间/地点,但是这不会发生在我的代码中的任何地方。 所以,我不知道我可以告诉你什么样的代码来帮助你。 编辑:我从头开始build立一个新的项目,删除所有其他variables..我把一个裸UIViewController到一个UINavigationController。 我把一个UIScrollView放到我的View中,查看整个视图的大小。 以下代码是整个项目。 事实certificate,这个问题(下面描述)只有在UIScrollView上的PAGING被启用后才会出现! 跆拳道? 🙂 这里是一个链接,下载一个基本的项目,只有几行代码来演示这个问题。 只要点击滚动视图,你会看到它随着边界的变化而变化。 http://inadaydevelopment.com/stackoverflow/WeirdScrollViews.zip 我怎么可以在我的滚动视图上启用分页,而不会在滚动和移动导航栏下的所有内容时出现界限? 可以将导航栏设置为不透明,避免出现问题,但理想情况是具有标准的iOS7行为,以便在内容视图放大后,允许内容位于导航栏下方,并通过半透明正常显示。 – (void) viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; NSArray *colors = @[ [UIColor blueColor], [UIColor orangeColor], [UIColor magentaColor], ]; NSArray *zoomerColors = […]

UIEdgeInsets在单元格上创build一个奇怪的乐队,我不知道如何解决它

我正在尝试使用UIEdgeInsetsMake将我的单元格的背景设置为渐变。 我已经尝试过多种方法来实现它,但是无论我使用什么,总会有一个问题。 我只是有两个静态单元格,我试图在willDisplayCell:设置他们的backgroundView 。 我有单独的图片的顶部,底部和中间的单元格,但由于我有两个单元格,我只需要顶部和底部。 这些是这些图像: 最佳 底部 在底部的顶部有一个缺失的线条,所以它们之间没有2pt线。 我稍微调整了底部的高度以补偿(高出1pt)。 这些图像是44x44pt。 我把它们设置如下: – (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 0) { UIImageView *topCellBackgroundImageView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"grouped-cell-bg-top"] resizableImageWithCapInsets:UIEdgeInsetsMake(5.0, 5.0, 5.0, 5.0)]]; cell.backgroundView = topCellBackgroundImageView; } // If it's the last row else if (indexPath.row == ([tableView numberOfRowsInSection:0] – 1)) { […]

将button图像alignment到UIButton的右边缘

有很多关于根据标题文本alignmentbutton图像的线程,但是我找不到将图像alignmentbutton右侧的任何内容。 这不起作用: button.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 50); 怎样才能正确的alignment一个button的图像? 它可以在故事板中完成吗?