我想将NSTextAttachment图像附加到我的属性字符串并使其垂直居中.
我使用以下代码来创建我的字符串
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:DDLocalizedString(@"title.upcomingHotspots") attributes:attrs];
NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
attachment.image = [[UIImage imageNamed:@"help.png"] imageScaledToFitSize:CGSizeMake(14.f, 14.f)];
cell.textLabel.attributedText = [str copy];
Run Code Online (Sandbox Code Playgroud)
但是,图像看起来与单元格textLabel的顶部对齐.
如何更改绘制附件的矩形?
如何在Swift中将可选闭包声明为属性?
我正在使用此代码:
var respondToButton:(sender: UIButton) -> Bool
Run Code Online (Sandbox Code Playgroud)
但编译器抱怨该属性未在初始化程序结束时初始化.我相信我可以通过将var声明为可选来解决这个问题,但是,我找不到正确的语法.
如何将此闭包属性声明为可选?
我想弄清楚为什么我在我的应用程序中遇到此崩溃.
它在使用ios5.1的模拟器中运行的Xcode 4.4中运行得非常好,但是当我切换到xcode 4.5和ios6时,我得到一个EXC_BAD_ACCESS代码2.这是我的代码:
- (void) myMethod
{
UIAlertView *alertview = [[[UIAlertView alloc]initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil] autorelease];
alertview.tag = 1
[alertview show];
}
Run Code Online (Sandbox Code Playgroud)
这是给我一个EXC_BAD_ACCESS码2上[UIAlertView show]
线
有任何想法吗?
谢谢!
我有一个关于设置视图大小的问题,我正在应用一些布局约束.
如何在不定义视图的情况下定义视图的大小?
我正在尝试创建一个高度固定且在屏幕原点具有原点的视图.它填充视图的宽度,以便在设备旋转时视图延伸到屏幕的宽度.这是我到目前为止所得到的......
self.containerView = [[HitTestContainerView alloc] init];
[self.containerView setBackgroundColor:[UIColor redColor]];
[self.view addSubview:self.containerView];
NSDictionary *viewsDictionary = @{@"view":self.containerView};
NSArray *verticalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-50-[view]-250-|" options:0 metrics:nil views:viewsDictionary];
NSArray *horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[view]|" options:0 metrics:nil views:viewsDictionary];
[self.view addConstraints:verticalConstraints];
[self.view addConstraints:horizontalConstraints];
Run Code Online (Sandbox Code Playgroud)
问题是除非我设置框架,否则我无法在屏幕上显示任何内容containerView
.在不使用Interface Builder的情况下执行此操作的正确方法是什么?
我正在尝试向我的NIB添加布局约束,我正在按照苹果提供的指示:
它说关于添加约束:
添加约束选择要为其添加约束的一个或多个对象.
从"编辑器">"添加约束"菜单中选择约束,或从"编辑器">"对齐"菜单中选择对齐类型.
Add Constraint菜单无法找到.是什么赋予了?我怎样才能添加约束?
是否有可能区分其中的情况
我的情况:过去,我已经提示用户通知权限,但我从未跟踪过请求.后来,我停止尝试注册任何通知设置.现在,我想重新介绍用户通知.
在应用程序中发生重大事件后,我的计划是显示某种UI,以解释选择加入用户通知的好处.但是,如果用户已拒绝,我宁愿显示一个可以将其带入Settings.app的单独UI.
目前,我正在使用-[UIApplication currentUserNotificationSettings]
抓取当前设置,但似乎这会返回UIUserNotificationTypeNone
上述两种情况.
push-notification apple-push-notifications ios ios-permissions
我正在尝试扩展UITableViewCell以显示更多内容.到目前为止,我已经关闭了动画,但我的问题是在动画完成之前出现了新内容.这是我的代码:
ps在配置单元格时,描述标签和读取按钮都以隐藏状态开始.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.selectedRow = indexPath;
SDJCell *cell = (SDJCell *)[tableView cellForRowAtIndexPath:indexPath];
[tableView beginUpdates];
[tableView endUpdates];
cell.descriptionLabel.hidden = NO;
cell.readButton.hidden = NO;
}
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
SDJCell *cell = (SDJCell *)[tableView cellForRowAtIndexPath:indexPath];
[tableView beginUpdates];
[tableView endUpdates];
cell.descriptionLabel.hidden = YES;
cell.readButton.hidden = YES;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if(selectedRow && indexPath.row == selectedRow.row) {
return 100;
}
return 44;
}
Run Code Online (Sandbox Code Playgroud)
关于如何在单元格完成后展示这些额外内容的任何想法?
谢谢!!
我在我的项目中有这个代码:
- (void) fadeImageView {
[UIView animateWithDuration:1.0f
delay:0
options:UIViewAnimationCurveEaseInOut
animations:^{
self.imageView.alpha = 0.0f;
}
completion:^(BOOL finished) {
//make the image view un-tappable.
//if the fade was canceled, set the alpha to 1.0
}];
}
Run Code Online (Sandbox Code Playgroud)
但是,有时我想在imageview变得不可见之前取消此操作.有没有办法取消动画中期动画?
我正在使用带有Flow布局的UICollectionView,并尝试根据AutoLayout约束使collectionView适当调整单元格的大小.
虽然单元格按预期工作,但我遇到的问题是我添加到CollectionView的任何补充视图的布局问题.
具体来说,在我滚动之后,在"校正"之前,在初始布局上,optionalView将处于错误的位置(即,y原点不正确).
作为参考,这是我如何配置我的单元格大小:
1.设置collectionViewLayout的估计项目大小
let collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
layout.estimatedItemSize = CGSizeMake(375, 50.0)
layout.minimumInteritemSpacing = 0.0
layout.minimumLineSpacing = 0.0
let view = UICollectionView(frame: CGRectZero, collectionViewLayout: layout)
view.backgroundColor = UIColor.whiteColor()
view.alwaysBounceVertical = true
return view
}()
Run Code Online (Sandbox Code Playgroud)
2.使用AutoLayoutCollectionViewCell的子类
class AutoLayoutCollectionViewCell: UICollectionViewCell {
override func preferredLayoutAttributesFittingAttributes(layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
layoutIfNeeded()
layoutAttributes.bounds.size.height = systemLayoutSizeFittingSize(UILayoutFittingCompressedSize).height
return layoutAttributes
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,此时,一切都按预期工作.
下一步是我们失败的地方.
3.提供标题的参考大小
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
return CGSizeMake(CGRectGetWidth(collectionView.frame), 30.0)
Run Code Online (Sandbox Code Playgroud)
}
我的问题是:为什么会这样?我怎样才能纠正这个问题?我怎么能处理自我调整其细胞大小的collectionView中的补充视图?
ios ×7
xcode ×4
objective-c ×2
swift ×2
autolayout ×1
ios6 ×1
quartz-core ×1
uialertview ×1
uianimation ×1
uilabel ×1
uitableview ×1
uiview ×1
xcode4.5 ×1