UICollectionViewCell的按下高亮效果

2016年11月21日 iOS 12条评论 阅读5296次

UICollectionView 中默认没有实现cell点击按下的高亮效果,本文往下是实现UICollectionViewCell按下出现高亮效果的方法



// 1. 定义cell正常的背景颜色和按下后高亮显示的背景颜色
#define CELL_COLOR_NORMAL [UIColor whiteColor]
#define CELL_COLOR_SELECTED [UIColor grayColor]


// 2. 实现UICollectionViewDataSource的方法
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    // cell点击变色
    UIView* selectedBGView = [[UIView alloc] initWithFrame:cell.bounds];
    selectedBGView.backgroundColor = CELL_COLOR_SELECTED;
    cell.selectedBackgroundView = selectedBGView; 
}



// 3. 实现UICollectionViewDelegate的方法
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
- (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
    [cell setBackgroundColor:CELL_COLOR_NORMAL];
}




OK .完成。


分享本文至:

WRITTEN BY

avatar
本文标签:UICollectionViewCell
看了本文是不是觉得很赞,那就赶紧点击下面按钮分享给身边的朋友吧!

12 条评论

  1. <a href="http://www.preloxlady.com/nike-hyperdunk-2015-flyknit-gul-lilla-butya">nike hyperdunk 2015 flyknit gul lilla</a> <a href="http://www.scalfarogroup.com/air-jordan-aero-mania-gris-argent-obuvc">air jordan aero mania gris argent</a> <a href="http://www.tubetotext.com/nike-air-max-thea-schuhe-swarovski-scarpea">nike air max thea schuhe swarovski</a> <a href="http://www.vapequalite.com/adidas-ultra-boost-uncaged-blanc-stripes-scarpee">adidas ultra boost uncaged blanc stripes</a> <a href="http://www.beylikduzufm.com/dam%C3%A4nner-nike-free-tr-blau-schwarz-obuvc">dam盲nner nike free tr blau schwarz</a> <a href="http://www.emmuscades.com/nike-blazer-mid-pelle-premium-femminile-scarpa-scarpea">nike blazer mid pelle premium femminile scarpa</a>
    oriturk http://www.oriturk.com/

  2. avatar myfraimz

    <a href="http://www.culturalsq.com/nike-zoom-alle-out-wei%C3%9F-schwarz-obuvc">nike zoom alle out wei脽 schwarz</a> <a href="http://www.tiaracara.com/nfl-brandon-williams-youth-limited-black-jersey-26-arizona-cardinals-nike-2016-salute-to-service-nflw">nfl brandon williams youth limited black jersey 26 arizona cardinals nike 2016 salute to service</a> <a href="http://www.shaunasbags.com/detroit-lions-jason-hanson-jersey-nflv">detroit lions jason hanson jersey</a> <a href="http://www.tomtaylorblog.com/grey-silver-womens-nike-roshe-print-shoes-skog">grey silver womens nike roshe print shoes</a> <a href="http://www.pistonari.com/nike-lunarglide-7-green-strike-law-skob">nike lunarglide 7 green strike law</a> <a href="http://www.rebeccastaste.com/new-york-yankees-retro-hat-ideas-hate">new york yankees retro hat ideas</a>
    myfraimz http://www.myfraimz.com/

  3. avatar amishcraftedgazebos

    <a href="http://www.cosmonet.net/nike-zoom-kobe-8-a-buon-mercato-scarpeb">nike zoom kobe 8 a buon mercato</a> <a href="http://www.cpgjoblist.net/air-jordan-retro-3-himmelbl%C3%A5-mintgr%C3%B8n-schuhed">air jordan retro 3 himmelbl氓 mintgr酶n</a> <a href="http://www.crosswindschurch.net/air-jordan-super-fly-bleu-rose-butyf">air jordan super fly bleu rose</a> <a href="http://www.cuttingedgeoffers.net/nike-free-run-3-rot-herren-obuve">nike free run 3 rot herren</a> <a href="http://www.cvceurope.net/jordan-retro-10-wolf-gris-and-rojo-obuvg">jordan retro 10 wolf gris and rojo</a> <a href="http://www.cyberlec.net/air-jordan-11-low-retro-university-azul-schuhef">air jordan 11 low retro university azul</a>
    amishcraftedgazebos http://www.amishcraftedgazebos.net/

  4. avatar ganuocdua

    <a href="http://www.culturalsq.com/304292-102-nike-dunk-low-pro-sb-zapatost">304292 102 nike dunk low pro sb</a> <a href="http://www.tiaracara.com/converse-femme-all-star-blanche-shoesz">converse femme all star blanche</a> <a href="http://www.shaunasbags.com/nike-flyknit-lunar-1-lyser%C3%B8d-sort-schuheb">nike flyknit lunar 1 lyser酶d sort</a> <a href="http://www.tomtaylorblog.com/youth-carson-wentz-limited-camo-nike-jersey-nfl-philadelphia-eagles-11-wentzylvania-rush-realtree-nflu">youth carson wentz limited camo nike jersey nfl philadelphia eagles 11 wentzylvania rush realtree</a> <a href="http://www.pistonari.com/nike-air-max-90-kids-pink-skou">nike air max 90 kids pink</a> <a href="http://www.rebeccastaste.com/flyknit-air-max-2014-blue-runningf">flyknit air max 2014 blue</a>
    ganuocdua http://www.ganuocdua.com/

  5. avatar irentevent

    <a href="http://www.kainjipark.com/white-leather-converse-shoesz">white leather converse</a> <a href="http://www.lapthelakes.com/air-jordan-retro-12-kvinners-r%C3%B8d-schuheb">air jordan retro 12 kvinners r酶d</a> <a href="http://www.delmaroffice.com/mens-nike-dallas-cowboys-73-larry-allen-navy-blue-alternate-vapor-untouchable-elite-player-nfl-jersey-nflu">mens nike dallas cowboys 73 larry allen navy blue alternate vapor untouchable elite player nfl jersey</a> <a href="http://www.medieneinsatz.com/adidas-ace-16.1-size-6-skou">adidas ace 16.1 size 6</a> <a href="http://www.linexcanton.com/nike-hypershift-purple-kit-runningf">nike hypershift purple kit</a> <a href="http://www.saskostomy.com/lebron-soldier-12-zapatosu">lebron soldier 12</a>
    irentevent http://www.irentevent.com/

  6. avatar chaiwanmei

    <a href="http://www.googleizate.com/nike-shox-current-vert-marron-kurpesd">nike shox current vert marron</a> <a href="http://www.kainstory.com/herre-ralph-lauren-london-olympic-lyser%C3%B8d-sort-polos">herre ralph lauren london olympic lyser酶d sort</a> <a href="http://www.matulat.com/nike-total-air-foamposite-max-azul-butyf">nike total air foamposite max azul</a> <a href="http://www.noteplays.com/ralph-lauren-pony-polo-bl%C3%A5-oransje-polou">ralph lauren pony polo bl氓 oransje</a> <a href="http://www.boozewrestler.com/nike-lebron-12-james-orange-r%C3%B8d-sort-chaussurese">nike lebron 12 james orange r酶d sort</a> <a href="http://www.dandrehobl.com/naruto-nike-dunks-for-vente-scarpef">naruto nike dunks for vente</a>
    chaiwanmei http://www.chaiwanmei.com/

  7. avatar altharmony

    <a href="http://www.albainmaz.com/huarache-ultra-wei%C3%9F-herren-for-verkauf-kurpesa">huarache ultra wei脽 herren for verkauf</a> <a href="http://www.seemyvcard.com/nike-magistax-p-roximo-street-tf-red-white-sneakerb">nike magistax p roximo street tf red white</a> <a href="http://www.joegauntlett.com/nike-huarache-purple-foot-locker-shoesg">nike huarache purple foot locker</a> <a href="http://www.rpnailsalon.com/new-orleans-saints-camouflage-hat-hats">new orleans saints camouflage hat</a> <a href="http://www.hrubinlaser.com/adidas-ultra-boost-3.0-black-on-feet-sneakerf">adidas ultra boost 3.0 black on feet</a> <a href="http://www.pruvitallday.com/mennns-salomon-xt-hawk-gr%C3%B8nn-himmelen-bl%C3%A5-obuvc">mennns salomon xt hawk gr酶nn himmelen bl氓</a>
    altharmony http://www.altharmony.com/

  8. avatar gccalifornia

    <a href="http://www.cpbetas.com/adidas-springblade-drive-2.0-bleu-ciel-noir-butyd">adidas springblade drive 2.0 bleu ciel noir</a> <a href="http://www.horecasummit.com/air-jordan-4-brot-sulit-obuvf">air jordan 4 brot sulit</a> <a href="http://www.kosahudson.com/asics-gel-sendai-2-jaune-orange-kurpesa">asics gel sendai 2 jaune orange</a> <a href="http://www.namkala.com/dam%C3%A4nner-nike-sb-stefan-janoski-max-alle-blau-kurpesf">dam盲nner nike sb stefan janoski max alle blau</a> <a href="http://www.qubellinfo.com/femmes-ralph-lauren-short-bleu-vert-poloz">femmes ralph lauren short bleu vert</a> <a href="http://www.sulukcum.com/adidas-ultra-boost-flash-rosa-scarpec">adidas ultra boost flash rosa</a>
    gccalifornia http://www.gccalifornia.com/

  9. avatar lbclubmitu

    <a href="http://www.chipcolley.com/kvinners-nike-kobe-9-low-gul-lilla-scarpef">kvinners nike kobe 9 low gul lilla</a> <a href="http://www.golfthebeach.com/femminile-nike-free-3.0-v5-australia-for-vendita-obuvc">femminile nike free 3.0 v5 australia for vendita</a> <a href="http://www.krzysztofkrol.com/nike-lebron-soldier-10-jaune-scarpea">nike lebron soldier 10 jaune</a> <a href="http://www.ondecktrivia.com/nike-hyperdunk-2016-low-lilla-guld-chaussuresg">nike hyperdunk 2016 low lilla guld</a> <a href="http://www.gopinksoccer.com/air-jordan-10-blanc-varsity-rouge-kurpesf">air jordan 10 blanc varsity rouge</a> <a href="http://www.iamfitshop.com/nike-free-3.0-v5-blau-blau-wei%C3%9F-illustrated-obuva">nike free 3.0 v5 blau blau wei脽 illustrated</a>
    lbclubmitu http://www.lbclubmitu.com/

  10. avatar z574shnx

    <a href="http://www.tvjuti65.com/maschio-aidas-boost-clima-chill-blu-butye">maschio aidas boost clima chill blu</a> <a href="http://www.pbyz412s.com/adidas-projoator-malice-jewelry-butye">adidas projoator malice jewelry</a> <a href="http://www.x745mfcu.com/vibram-fivefingers-classic-sort-orange-schuhea">vibram fivefingers classic sort orange</a> <a href="http://www.dkouevy6.com/nike-huarache-ultra-hvid-bl%C3%A5-hvid-chaussuresa">nike huarache ultra hvid bl氓 hvid</a> <a href="http://www.15wij42f.com/air-jordan-7-nero-citrus-obuva">air jordan 7 nero citrus</a> <a href="http://www.5k71d4ly.com/nike-free-run-2-noir-vente-butyd">nike free run 2 noir vente</a>
    z574shnx http://www.z574shnx.com/

  11. avatar epointsclub

    <a href="http://www.agriind.com/flyknit-lunar-2-mens-mens-skoc">flyknit lunar 2 mens mens</a> <a href="http://www.rapheroes.com/billig-nike-flyknit-lunar-3-dam%C3%A4nner-wei%C3%9F-skob">billig nike flyknit lunar 3 dam盲nner wei脽</a> <a href="http://www.odubmusic.com/adidas-superstar-2-light-blau-shoesv">adidas superstar 2 light blau</a> <a href="http://www.kidbleach.com/billig-nike-air-max-flair-kvinders-r%C3%B8d-runninga">billig nike air max flair kvinders r酶d</a> <a href="http://www.shoppula.com/ray-ban-justin-vs-andy-sunglassesr">ray ban justin vs andy</a> <a href="http://www.kanpourakuen.com/reebok-gl-6000-white-shoesv">reebok gl 6000 white</a>
    [url=http://www.epointsclub.com/]epointsclub[/url]

  12. avatar gonencymm

    <a href="http://www.nomorbogor.com/asics-gel-noosa-tri-10-menns-s%C3%B8lv-sneakerb">asics gel noosa tri 10 menns s酶lv</a> <a href="http://www.sozihoster.com/nike-flyknit-lunar-1-atomic-pink-kaufen-skod">nike flyknit lunar 1 atomic pink kaufen</a> <a href="http://www.allbidder.com/christian-louboutin-outlet-houston-texas-louboutine">christian louboutin outlet houston texas</a> <a href="http://www.yrlogoworks.com/pandora-princess-ring-stack-pandorar">pandora princess ring stack</a> <a href="http://www.sateambeast.com/ray-ban-rb4057-sunglasses-womens-sunglassesf">ray ban rb4057 sunglasses womens</a> <a href="http://www.druckberg.com/prada-pink-sunglasses-pradar">prada pink sunglasses</a>
    gonencymm http://www.gonencymm.com/

欢迎留言




用户登录

sitemap