2013-10-31 17 views
5

Sto cercando di aggiungere un customBadge come una visualizzazione secondaria di un UIButton -Aggiunta di una visualizzazione secondaria per UIButton

questo è il mio codice finora -

//msg count initiaition 
//CustomBadge *customBadge1 = [CustomBadge customBadgeWithString:@"2"]; 
CustomBadge *customBadge1 = [CustomBadge customBadgeWithString:@"2" 
               withStringColor:[UIColor whiteColor] 
               withInsetColor:[UIColor redColor] 
               withBadgeFrame:YES 
              withBadgeFrameColor:[UIColor redColor] 
                withScale:2.0 
                withShining:YES]; 

    // Set Position of Badge 1 
[customBadge1 setFrame:CGRectMake(self.view.frame.size.width/2-customBadge1.frame.size.width/2+_MsgHeadBtn.frame.size.width/2, 110, customBadge1.frame.size.width, customBadge1.frame.size.height)]; 
//add badge to view 
[_MsgHeadBtn addSubview:customBadge1]; 

Il pulsante che sto cercando di aggiungere il la sottoview è _MsgHeadBtn, che è l'icona dell'email in alto a sinistra dello screenshot qui sotto. Stavo cercando di rendere il badge personalizzato visualizzato leggermente sopra e alla destra dell'icona della posta elettronica, ma alla fine ottengo il risultato nello screenshot!

enter image description here

Chiunque può offrire qualche consiglio su dove sto andando male !?

risposta

5

Il problema rientra nel metodo setFrame:. Stai utilizzando self.view.frame.size.width.

Verificare con questo codice:

[customBadge1 setCenter:CGPointMake(_MsgHeadBtn.frame.size.width, 0)]; 
[_MsgHeadBtn addSubview:customBadge1]; 

o

[customBadge1 setFrame:CGRectMake(_MsgHeadBtn.frame.size.width, 0, customBadge1.frame.size.width, customBadge1.frame.size.height)]; 
[_MsgHeadBtn addSubview:customBadge1]; 
+0

direi: '[customBadge1 SETFRAME: CGRectMake (_MsgHeadBtn.frame .size.width, 0, customBadge1.frame.size.width, customBadge1.frame.size.height)]; ' – sergio

+0

@sergio: Grazie per le informazioni. Ho appena modificato la mia risposta :) –

+0

funziona - bella! – Dancer

1

regolare il telaio come di seguito:

[customBadge1 setFrame:CGRectMake(_MsgHeadBtn.frame.size.width-customBadge1.frame.size.width,-customBadge1.frame.size.height/2, customBadge1.frame.size.width, customBadge1.frame.size.height)];