|
最近優(yōu)化升級(jí)了之前做的一個(gè)項(xiàng)目,現(xiàn)在這一期已接近尾聲了,今天可以騰出些時(shí)間總結(jié)一下最近項(xiàng)目中用的比較多的圖片文字混排顯示的內(nèi)容。現(xiàn)在遇到比較多的圖文混排的基本有三種:一種是在標(biāo)簽中顯示 價(jià)格符號(hào)+價(jià)格+某種內(nèi)部項(xiàng)目單位(如糧票符號(hào))+數(shù)量,這種在項(xiàng)目中用的比較多些;第二種是商品詳情中展示一段文字+一組圖片或者是,一段文字+一張圖片的數(shù)組形式展示,這種在詳情中用的也不少;還有一種的和第二種類似,像是網(wǎng)頁(yè)中的東西,這里就不多說了;下面說說前兩種比較常用的圖文混排展示的方式; 1、 NSString *temStr = [NSString stringWithFormat:@"¥%.2f + ",[price floatValue]-[score floatValue]]; NSTextAttachment* attach = [[NSTextAttachment alloc] init]; attach.image = [UIImage imageNamed:@"P灰色列表糧票符號(hào).png"]; NSAttributedString* attStr1 = [NSAttributedString attributedStringWithAttachment:attach]; NSMutableAttributedString* attStr = [[NSMutableAttributedString alloc] initWithAttributedString:attStr1]; NSMutableAttributedString *strMatt = [[NSMutableAttributedString alloc] initWithString:temStr]; //在圖片前面插入一段文字 [attStr insertAttributedString:strMatt atIndex:0]; //在圖片后面追加一段文字 [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%.2f",[score floatValue]]]]; //設(shè)置圖片的大小 attach.bounds = CGRectMake(0, 0, 8, 9); cell.lblrealprice.attributedText = attStr; 2、在詳情中實(shí)現(xiàn)圖文混排的方式 |
|
|