小编Eri*_*eut的帖子

iOS弹出关闭按钮标签:"OK"或"Okay"?

我正在开发一个带有自定义弹出警报的iPhone应用程序.在设计中,这些警报都有"取消"按钮,但由于在这些情况下无法取消,我想将它们更改为"正常"按钮.

我的问题是:关于这些按钮标签的Apple指南是什么?应该是"Okay"(这是我个人的偏好),还是应该是"OK"(我不喜欢它,因为它看起来像青少年文字说话或俄克拉荷马州的缩写).

iphone alert popup button ios

8
推荐指数
2
解决办法
2073
查看次数

在Swift中,如何将格式化的Int值插入String?

这似乎是一个超级基本的问题,但我似乎无法在任何地方找到答案:-(我能够在Objective C中做到这一点,但我陷入了Swift的困境.

我需要做什么:

  1. 取整数值
  2. 将其格式化为本地化字符串
  3. 使用stringWithFormat等效方法将值注入另一个字符串(因为另一个字符串也是本地化的,下面的简化示例中未显示)

如何在Objective C中轻松完成- 这有效:

    // points is of type NSNumber *

    NSNumberFormatter *formatter = [NSNumberFormatter new];
    formatter.locale             = [NSLocale currentLocale];
    formatter.numberStyle        = NSNumberFormatterDecimalStyle;

    NSString *ptsString = [formatter stringFromNumber:points];
    NSString *message   = [NSString stringWithFormat:@"You've earned %@ points", ptsString];
Run Code Online (Sandbox Code Playgroud)

我最好尝试在Swift中执行此操作- 最后一行编译错误:

    // points is of type Int

    let formatter         = NSNumberFormatter()
    formatter.locale      = NSLocale.currentLocale()
    formatter.numberStyle = NSNumberFormatterStyle.DecimalStyle

    let ptsString = formatter.stringFromNumber(points)!
    let message   = String(format: "You've earned %@ points", arguments: ptsString) …
Run Code Online (Sandbox Code Playgroud)

string stringwithformat nsnumberformatter ios swift

4
推荐指数
2
解决办法
1万
查看次数

如何在UITableViewCell中垂直对齐UIButton?(目标C)

我有一个自定义表格单元,我想在左侧向其中添加一个自定义UIButton,使其垂直居中。我尝试使用下面显示的代码来实现此目的,这些代码在我的自定义表格单元实现中。

我正在尝试通过获取self.frame的高度并调整按钮的大小来实现垂直居中对齐,以使其从单元格的顶部和底部出现5px。当我运行此按钮时,我看到按钮从顶部出现5像素,但从底部出现更多(20像素左右)。

什么是实现垂直对齐的正确方法?

这是我在定制表单元格实现中的代码:

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
  self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  if (self)
  {
    [self setSelectionStyle:UITableViewCellSelectionStyleNone];

    // Create the audio button on the left side:
    self.audioButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.audioButton.frame = CGRectMake(5, 5, self.frame.size.height - 10, self.frame.size.height - 10);
    [self.audioButton setImage:[UIImage imageNamed:@"ec-icon-speaker.png"] forState:UIControlStateNormal];
    [self.audioButton addTarget:self
                    action:@selector(playWordAudio)
          forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.audioButton];
Run Code Online (Sandbox Code Playgroud)

感谢您的任何建议,

埃里克

objective-c vertical-alignment uibutton uitableview ios

3
推荐指数
1
解决办法
4547
查看次数

调用[UIColor colorWithRed:green:blue:alpha:]导致可怕的崩溃

摘要:

在UITextField的子类中:

  • [UIColor colorWithRed:green:blue:alpha] 导致应用程序崩溃
  • [UIColor greenColor] 工作正常没有任何问题

怎么可能?

回答:

事实证明,问题layoutSubviews在于我正在调用正在使用的方法colorWithRed.显然会colorWithRed分配额外的内存,这会导致问题.(感谢Johannes Fahrenkrug在评论中指出它可能是其他东西 - 见下文.)

详情:

在作为UITextField的子类的ECTextField类中,当我进行以下调用时,我遇到了可怕的崩溃:

[self setTextColor:[UIColor colorWithRed:42/255.0 green:170/255.0 blue:42/255.0 alpha:0.8]];
Run Code Online (Sandbox Code Playgroud)

该应用程序冻结,挂起,然后一段时间后我收到以下错误:

SampleApp(58375,0x34f71a8) malloc: *** mach_vm_map(size=1048576) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
2013-11-14 22:25:11.929 SampleApp[58375:907] *** Terminating app due to uncaught exception 'NSMallocException', reason: '*** NSAllocateObject(): attempt to allocate object of class 'NSPathStore2' failed'
*** First throw call stack:
(0x2362012 0x2166e7e 0x2361deb 0x1b5bcf2 …
Run Code Online (Sandbox Code Playgroud)

objective-c uicolor ios

0
推荐指数
2
解决办法
1099
查看次数