2013-03-15 47 views
0

我已经打牌游戏,我增加了一个形象为卡背面但画面是所有的地方,我不能FINT问题的updateUI方法..广东话调整的UIImage的正确

这是我的方法:我如何调整它以匹配卡的大小?

- (void)updateUI { 

    for (UIButton *cardButton in self.cardButtons) { 
     Card *card = [self.game cardAtIndex:[self.cardButtons indexOfObject:cardButton]]; 
     [cardButton setTitle:card.contents forState:UIControlStateSelected]; 
     [cardButton setTitle:card.contents 
        forState:UIControlStateSelected|UIControlStateDisabled]; 
     cardButton.selected = card.isFaceUp; 
     cardButton.enabled = !card.isUnplayable; 
     cardButton.alpha = card.isUnplayable ? 0.3 : 1.0; 

     cardButton.imageEdgeInsets = UIEdgeInsetsMake(2, 2, 2, 2); 
     UIImage *cardBackImage = (cardButton.selected) ? nil : [UIImage imageNamed:@"benCardImag.png"]; 
     [cardButton setImage:cardBackImage forState:UIControlStateNormal]; 

    } 

    self.scoreCounter.text = [NSString stringWithFormat:@"Score: %d", self.game.score]; 

    if (self.game.notification) { 

     self.notificationLabel.text = self.game.notification; 

    } 
} 

回答

1

使用setBackgroundImage:forState:而不是setImage:forState:。图像被调整到文本的左侧,但背景图像被缩放以填充按钮。如果要控制图像和文本的位置,您可能还想尝试自定义的UIControl而不是UIButton。

+0

很酷的感谢分配,但我也可以让长方形角落的bg图像真正的cardbutton?所以bg图像实际上看起来像卡片,而不仅仅是一个方形bg。也当我点击它时,它给我回卡形状,​​所以它看起来很时髦.. – MNY 2013-03-15 23:25:08

+0

尝试设置按钮层的cornerRadius和使用自定义按钮,而不是一个RoundRect按钮。如果这不起作用,你可能不得不实现你自己的按钮。 – Aleph7 2013-03-15 23:29:42

+0

当你说“你自己”,你的意思是像设计一些与Photoshop? @Aleph – MNY 2013-03-15 23:36:27