小编the*_*ick的帖子

UIButton标签文本正在被剪裁

我有一个内置于Interface Builder的UIButton,它有一个默认标签.在Xcode中,我正在动态更改标签文本:

myButton.titleLabel.text = @"this is the new label";
Run Code Online (Sandbox Code Playgroud)

但是,当文本更新时,新字符串将被剪切为与原始字符串相同的大小,最终看起来像:

this...label
Run Code Online (Sandbox Code Playgroud)

任何人都知道为什么会这样吗?

iphone cocoa-touch uibutton

38
推荐指数
4
解决办法
3万
查看次数

在屏幕上随机移动对象

我正在尝试动画UIButton以在不同方向上随机移动屏幕.下面的代码很有用.按钮将开始沿着随机路径移动,然而,它继续在A点和B点之间来回移动.

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:1]; 
[UIView setAnimationRepeatCount:1000]; 
[UIView setAnimationRepeatAutoreverses:YES]; 

CGFloat x = (CGFloat) (arc4random() % (int) self.view.bounds.size.width); 
CGFloat y = (CGFloat) (arc4random() % (int) self.view.bounds.size.height); 

CGPoint squarePostion = CGPointMake(x, y); 
button.center = squarePostion; 

[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)

每次改变方向时,我怎样才能让它继续移动到一个新的随机点,而不是简单地来回移动?

谢谢!

iphone xcode objective-c ios

6
推荐指数
1
解决办法
6679
查看次数

从字典对象中获取密钥?

我有一个字典设置如下.如何从中获取实际键值(演员姓名)objectAtIndex:1

<plist version="1.0">
<dict>
    <key>Brad Pitt</key>
    <array>
        <string>Fight Club</string>
        <string>Seven</string>
        <string>Inglorious Basterds</string>
        <string>Babel</string>
    </array>
    <key>Meryl Streep</key>
    <array>
        <string>Adaptation</string>
        <string>The Devil Wears Prada</string>
        <string>Doubt</string>
        <string>Julie &amp; Julia</string>
    </array>
    <key>Chris Cooper</key>
    <array>
        <string>Adaptation</string>
        <string>American Beauty</string>
        <string>The Bourne Identity</string>
        <string>October Sky</string>
    </array>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)

iphone objective-c plist

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

UIView动画块无法正常工作

一旦游戏中剩下不到10秒的时间,我试图让我的计时器闪烁红色.出于某种原因,动画无效.timeLabel只是变白并保持这种状态.这是我正在使用的代码:

if (timeLeft <= 9 && timeLeft > 0) {
    timeLabel.textColor = [UIColor redColor];

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationDelegate:self];
    timeLabel.textColor = [UIColor whiteColor];
    [UIView commitAnimations];
}
Run Code Online (Sandbox Code Playgroud)

奇怪的是,我在另一个应用程序中使用完全相同的代码块.也许我班上的某个地方有另一个动画干扰了这个动画?

iphone xcode objective-c ios

0
推荐指数
1
解决办法
2496
查看次数

标签 统计

iphone ×4

objective-c ×3

ios ×2

xcode ×2

cocoa-touch ×1

plist ×1

uibutton ×1