如果我使用autolayout安排了UIButton,它的大小可以很好地调整以适应其内容.
如果我将图像设置为button.image,则内在大小似乎再次考虑到这一点.
但是,如果我调整titleEdgeInsets按钮的按钮,布局不会考虑到这一点,而是截断按钮标题.
如何确保按钮的固有宽度占据插入?

编辑:
我使用以下内容:
[self.backButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
Run Code Online (Sandbox Code Playgroud)
目标是在图像和文本之间添加一些分隔.
我正在尝试在UICollectionViewController中处理接口方向更改.我想要实现的是,我想在接口旋转后拥有相同的 contentOffset.意思是,它应该根据边界变化的比例进行更改.
从肖像开始,内容偏移量为{ bounds.size.width*2,0} ...

...应该导致景观中的内容偏移{ bounds.size.width*2,0}(反之亦然).

计算新的偏移量不是问题,但不知道,在何处(或何时)设置它以获得平滑的动画.我正在做的事情是使布局无效willRotateToInterfaceOrientation:duration:并重置内容偏移didRotateFromInterfaceOrientation::
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration;
{
self.scrollPositionBeforeRotation = CGPointMake(self.collectionView.contentOffset.x / self.collectionView.contentSize.width,
self.collectionView.contentOffset.y / self.collectionView.contentSize.height);
[self.collectionView.collectionViewLayout invalidateLayout];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
{
CGPoint newContentOffset = CGPointMake(self.scrollPositionBeforeRotation.x * self.collectionView.contentSize.width,
self.scrollPositionBeforeRotation.y * self.collectionView.contentSize.height);
[self.collectionView newContentOffset animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
这会在旋转后更改内容偏移.
如何在旋转期间设置它?我试图设置新的内容偏移量,willAnimateRotationToInterfaceOrientation:duration:但这会导致一种非常奇怪的行为.
我正在寻找一种方法来padding向UIView 添加属性.理想情况下,我想避免子类化并将其放入类别中.用法如下:
myview.padding = UIEdgeInsetsMake(10, 10, 10, 10);
Run Code Online (Sandbox Code Playgroud)
也许还有一个paddingBox属性,它将返回CGRect描述内部填充盒的大小和位置.
现在,如何在类别中实现类似的东西.我最初虽然使用bounds,但不幸的bounds是,它的大小与frame(总是相同)的大小相关联,只有坐标可以不同.
我有一张普通风格的桌子,只有一个部分.我实现viewForHeaderInSection:了在节标题中添加自定义视图.
我无法在表格节标题视图和第一个单元格之间看到分隔线.[见附图]

我究竟做错了什么?
我正在使用UIPanGestureRecognizer来识别UITableView中的水平滑动(准确地说在单元格上,尽管它被添加到表本身).然而,这个手势识别器显然从表中窃取了触摸.我已经有了pangesturerecognizer来识别水平滑动,然后对齐; 但是如果用户通过垂直滑动开始,它应该将该触摸的所有事件传递给tableview.
我尝试过的一件事是禁用识别器,但它不会滚动直到下一个触摸事件.所以我需要它立即通过该活动.
我尝试的另一件事就是让它自己滚动,但是在停止触摸后你会错过持久的速度.
下面是一些代码:
//In the viewdidload method
UIPanGestureRecognizer *slideRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(sliding:)];
[myTable addGestureRecognizer:slideRecognizer];
-(void)sliding:(UIPanGestureRecognizer *)recognizer
{
if (recognizer.state == UIGestureRecognizerStateBegan)
{
CGPoint translation = [recognizer translationInView:favoritesTable];
if (sqrt(translation.x*translation.x)/sqrt(translation.y*translation.y)>1) {
horizontalScrolling = YES; //BOOL declared in the header file
NSLog(@"horizontal");
//And some code to determine what cell is being scrolled:
CGPoint slideLocation = [recognizer locationInView:myTable];
slidingCell = [myTable indexPathForRowAtPoint:slideLocation];
if (slidingCell.row == 0) {
slidingCell = nil;
}
}
else
{
NSLog(@"cancel");
}
if (recognizer.state == UIGestureRecognizerStateEnded …Run Code Online (Sandbox Code Playgroud) iphone cocoa-touch objective-c uitableview uigesturerecognizer
我想问一个关于iPhone应用程序上的目标C的问题.我在apple开发者网站上阅读了一些示例程序,我发现几乎所有的应用程序都包含一个名为"NSBundle"和"mainBundle"的单词,我真的不明白这个单词的含义.谁能告诉我这件事?非常感谢你.
我正在尝试为typealias符合多个协议的UITableViewCell的委托属性定义一个.这就是我想要做的,Swift抱怨我的语法错误:
// The typealias definition
typealias CellDelegate = AnyObject<UIPickerViewDataSource, UIPickerViewDelegate>
// In my UITableViewCell subclass:
weak var delegate: CellDelegate?
Run Code Online (Sandbox Code Playgroud)
"不能专门化非泛型类型AnyObject"是我得到的错误.我该怎么做呢?
我已经创建了一个自定义单元格来加载到表格中.界面已经完成,现在我正在尝试链接xib和类.
我打开了分屏视图,我尝试控制拖动项目,以便Xcode可以为我建立连接.当我填写名称并单击连接时,我收到一个错误:
无法插入新的插座连接:无法将源代码插入URL中的文档://localhost/Users/Velox/Projects/CompanyName/ProjectName/ProjectName/HistoryCell.m,因为它不包含名为HistoryCell的类的类定义.
我已将xib的自定义类设置为HistoryCell.
我在这里错过了什么?
谢谢.
我试图使用一个UIRefreshControl内部我UITableViewController自己在里面UINavigationController,它的hidesNavigationBar属性设置为NO(所以导航栏是可见的).
该UIRefreshControl作品,但被掩盖UINavigationBar.我很惊讶我找不到其他遇到这个问题的人.
可能的相关要点:
rootViewController认为我UIWindow是我的UINavigationController.UINavigationController通过设置viewControllers属性来设置初始视图控制器UINavigationController.UITableViewController子类用nib实例化.UIRefreshControl在viewDidLoad我的UITableViewController子类的方法中实例化我.我在这个方法中设置了子类的refreshControl属性UITableViewController.UIRefreshControl工作完全正常,我可以看到它的一部分,但它是由我的遮蔽UINavigationBar.如果我设置hidesNavigationBar为YES(但我不想隐藏它),这看起来完全正常.用于创建和定位我的代码UIRefreshControl是:
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self
action:@selector(toggleRefresh:)
forControlEvents:UIControlEventValueChanged];
self.refreshControl = refreshControl;
Run Code Online (Sandbox Code Playgroud)
这段代码片段在viewDidLoad我的UITableViewController子类的方法中,它是一个子视图控制器UINavigationViewController.
cocoa-touch uitableview uinavigationcontroller ios uirefreshcontrol
我UIView在界面构建器上有一个.在我的视图控制器中,我有一个IBOutlet MyUIView指向UIView界面构建器.
我将类更改UIView为" MyUIView"(自定义UIView类),但似乎没有init触发子类的任何方法.
我究竟做错了什么?
cocoa-touch ×9
ios ×8
objective-c ×4
uikit ×4
uitableview ×4
uiview ×3
iphone ×2
autolayout ×1
cocoa ×1
nsbundle ×1
swift ×1
uibutton ×1
uiscrollview ×1