我在做一个应用程序,我用UIEdgeInsetsMake了resizableImageWithCapInsets,但我不明白是怎么做的工作原理完全,UIEdgeInsetsMake有4个参数:
但它们是漂浮的,所以我不知道如何将其设置为图像,谢谢!:d
我有一个CGRect,我想调整它UIEdgeInsets.
似乎可能有一个内置函数可以做到这一点.我已经找了一个CGRectAdjustByInsets或带有其他CGRect…前缀的函数,但我没有找到任何东西.
我应该自己编码吗?
我有一个UITextView并设置内容插入
[atextView setContentInset:UIEdgeInsetsMake(0, 10, 0, 0)];
此代码在iOS 6.1及更低版本中运行,但在iOS 7.0中没有任何反应.
关于根据标题文本对齐按钮图像有很多线索,但我找不到任何关于将图像对齐到按钮右侧的信息.
这没有效果:
button.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 50);
Run Code Online (Sandbox Code Playgroud)
如何将图像右键对齐按钮?可以在故事板中完成吗?
我想创建一个UIButton,但是比图像有更大的拍子区域.(例如:40x40按钮,但图像仅为20x20,居中).
这imageEdgeInsets是为了什么?
我已经以编程方式设置它:(这是在包含我的按钮的UIView中)
- (void)awakeFromNib {
[_plusButton setImageEdgeInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
[_plusButton setContentMode:UIViewContentModeCenter];
}
Run Code Online (Sandbox Code Playgroud)
并从故事板

但它们似乎都不起作用.
我是iOS应用程序开发的新手,想知道如何UIEdgeInsets在按钮中使用属性,所以请指导我.
Simliar到iOS Photos App,用户通过捏合放大和缩小图像:
UIView> UIScrollView> UIImageView> UIImage
最初,我遇到了缩放比例1以下的问题:图像偏离中心.我通过这样做得到了解决方法:
func scrollViewDidZoom(scrollView: UIScrollView) {
let offsetX = max((scrollView.bounds.width - scrollView.contentSize.width) * 0.5, 0)
let offsetY = max((scrollView.bounds.height - scrollView.contentSize.height) * 0.5, 0)
scrollView.contentInset = UIEdgeInsetsMake(offsetY, offsetX, 0, 0)
}
Run Code Online (Sandbox Code Playgroud)
这在缩小时效果很好.
UIImage内容模式是aspectFit
当我ZOOM IN时,当zoomScale大于1时,滚动视图插图需要拥抱滚动视图包含的UIImage的周围环境.这消除了UIImage周围的死空间.IE,照片应用程序通过捏或双击放大.
func scrollViewDidZoom(scrollView: UIScrollView) {
if scrollView.zoomScale > 1 {
let imageScale = (self.imageView.bounds.width/self.imageView.image!.size.width)
let imageWidth = self.imageView.image!.size.width * imageScale
let imageHeight = self.imageView.image!.size.height * imageScale
scrollView.contentInset = UIEdgeInsetsMake(((scrollView.frame.height - imageHeight) * 0.5), (scrollView.frame.width - imageWidth) …Run Code Online (Sandbox Code Playgroud) 在iOS 6中使用自动布局时,UIButton的内在内容大小似乎包含按钮文本周围约10px的填充.有没有办法控制这个填充值?例如,我希望能够做到这样的事情,将每边的填充设置为5px:
[button setPadding:UIEdgeInsetsMake(5, 5, 5, 5)];
Run Code Online (Sandbox Code Playgroud)
我试过设置contentEdgeInsets,titleEdgeInsets和imageEdgeInsets都无济于事.奇怪的是,在contentEdgeInsets中指定负左值或右值似乎有一些效果,但不是顶部或底部.
无论哪种方式,我希望能够将实际填充值指定为正数,而不是将默认值调整为表示为负数.任何人都知道这是否可行?
使用Swift 4.2和Xcode 10 beta,如果我写:
import UIKit
let foo: UIEdgeInsets = .zero
Run Code Online (Sandbox Code Playgroud)
然后我在编译时遇到致命错误:
*** DESERIALIZATION FAILURE (please include this section in any bug report) ***
result is ambiguous
0 swift 0x000000010784fc5a PrintStackTraceSignalHandler(void*) + 42
1 swift 0x000000010784f066 SignalHandler(int) + 966
2 libsystem_platform.dylib 0x00007fff62a5ef5a _sigtramp + 26
3 libsystem_platform.dylib 0x0000000000000010 _sigtramp + 2639925456
4 libsystem_c.dylib 0x00007fff627fc1ae abort + 127
5 swift 0x0000000104cf599b swift::ModuleFile::fatal(llvm::Error) + 1915
6 swift 0x0000000104d2d4d2 swift::SILDeserializer::readGlobalVar(llvm::StringRef) + 1890
7 swift 0x0000000104dd7f9a swift::SerializedSILLoader::getAllForModule(swift::Identifier, swift::FileUnit*) + 234
8 swift 0x0000000103b2adbe performCompile(swift::CompilerInstance&, …Run Code Online (Sandbox Code Playgroud) 我正在尝试将UIEdgeInsetsMake我的单元格的背景设置为渐变.我已尝试过多种方法让它发挥作用,但无论我使用什么,总会出现问题.
我只是有两个静态细胞,在那里我试图设置他们backgroundView在willDisplayCell:.我有顶部,底部和中间单元的单独图像,但由于我有两个单元格,我只需要顶部和底部.这些是这些图像:
最佳

底部

底部顶部有一条缺失线,因此它们之间没有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)) {
UIImageView *bottomCellBackgroundImageView =
[[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"grouped-cell-bg-bottom"]
resizableImageWithCapInsets:UIEdgeInsetsMake(5.0, 5.0, 5.0, 5.0)]];
cell.backgroundView = bottomCellBackgroundImageView;
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
Run Code Online (Sandbox Code Playgroud)
这不行.正如您在下面的图片中所看到的,在顶部单元格中,整个单元格中有一条1pt白色"带",看起来非常难看.我不知道为什么会这样.

所以我改变了它的topCellBackgroundView边缘插入(5.0, 5.0, …
uiedgeinsets ×10
ios ×8
uibutton ×3
xcode ×3
objective-c ×2
uiimage ×2
autolayout ×1
cgrect ×1
cocoa-touch ×1
ios5 ×1
ios7 ×1
iphone ×1
swift ×1
swift4.2 ×1
uiimageview ×1
uiscrollview ×1
uitableview ×1
uitextview ×1
xcode10 ×1
zoom ×1