標籤:style blog http color strong width
iOS開發項目—07圖片展開
一、簡單說明
1.代碼說明:
圖片處理代碼:
1 + (UIImage *)resizedImage:(NSString *)name2 {3 UIImage *image = [UIImage imageWithName:name];4 return [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5];5 }6 //以長度的一半,高度的一半為中心進行展開。
調用展開(1)
1 /** 2 * 點擊標題點擊 3 */ 4 - (void)titleClick:(UIButton *)titleButton 5 { 6 // 換成箭頭向上 7 [titleButton setImage:[UIImage imageWithName:@"navigationbar_arrow_up"] forState:UIControlStateNormal]; 8 9 10 // 快顯功能表11 UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];12 button.backgroundColor = [UIColor blueColor];13 14 15 HMPopMenu *menu = [[HMPopMenu alloc ] initWithContentView:nil];16 menu.delegate = self;17 menu.arrowPosition = HMPopMenuArrowPositionCenter;18 // menu.dimBackground = YES;19 [menu showInRect:CGRectMake(0, 0, 100, 200)];20 }
效果:
2.快顯功能表存在的問題:當寬度大於217的時候,就會有問題。
代碼:
1 /** 2 * 點擊標題點擊 3 */ 4 - (void)titleClick:(UIButton *)titleButton 5 { 6 // 換成箭頭向上 7 [titleButton setImage:[UIImage imageWithName:@"navigationbar_arrow_up"] forState:UIControlStateNormal]; 8 9 // 快顯功能表10 UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];11 button.backgroundColor = [UIColor blueColor];12 13 HMPopMenu *menu = [[HMPopMenu alloc ] initWithContentView:nil];14 menu.delegate = self;15 menu.arrowPosition = HMPopMenuArrowPositionCenter;16 // menu.dimBackground = YES;17 [menu showInRect:CGRectMake(0, 0, 300, 200)];18 }
實現效果:
產生問題的原因:展開圖片的方式不對。展開讓箭頭的實現出現了問題,可以嘗試換一種展開的方式。
之前的展開是對中間的百分之五十進行展開,變換為展開最右邊的部分也不能徹底的解決問題。
說明:新浪官方在面對這個問題的時候,美工把菜單的圖片設定的很大,為434,所以如果展開的範圍在217內,那就不會有影響。(調整CGRectMake的寬度),在做上邊有小箭頭的圖片時,把圖片的寬度做足一點。