UICollectionViewCell的按下高亮效果

2016年11月21日 iOS 20条评论 阅读6140次

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
看了本文是不是觉得很赞,那就赶紧点击下面按钮分享给身边的朋友吧!

20 条评论

  1. <a href="http://www.feelsafeinc.com/nike-air-max-2016-femminile-argento-gituttio-butya">nike air max 2016 femminile argento gituttio</a> <a href="http://www.gaeconomics.com/nike-dunk-ac-naranja-schuheg">nike dunk ac naranja</a> <a href="http://www.garagesetcinc.com/ralph-lauren-tees-wei%C3%9F-rot-polou">ralph lauren tees wei脽 rot</a> <a href="http://www.paleofasting.com/kvinners-nike-zoom-pegasus-31-gr%C3%A5-gul-chaussuresa">kvinners nike zoom pegasus 31 gr氓 gul</a> <a href="http://www.revarepair.com/kvinders-nike-air-max-thea-sort-anthracite-hvid-wolf-gr%C3%A5-schuhed">kvinders nike air max thea sort anthracite hvid wolf gr氓</a> <a href="http://www.saraviquez.com/nike-flyknit-lunar-3-gr%C3%A5-orange-urine-scarpea">nike flyknit lunar 3 gr氓 orange urine</a>
    marcofabrin http://www.marcofabrin.com/

  2. <a href="http://www.sophiecrooks.com/air-jordan-super.fly-5-nero-oro-scarpel">air jordan super.fly 5 nero oro</a> <a href="http://www.hkelitemodels.com/bon-march%C3%A9-nike-free-4.0-flynit-femmes-rouge-noir-chaussuresh">bon march茅 nike free 4.0 flynit femmes rouge noir</a> <a href="http://www.graciecomm.com/nike-magista-onda-fg-nero-scarpeh">nike magista onda fg nero</a>
    firagandia http://www.firagandia.com/

  3. <a href="http://www.romoautocare.com/nike-foamposite-oranger-rose-chaussuresl">nike foamposite oranger rose</a> <a href="http://www.industrialegy.com/nike-air-max-zero-mujeres-rosado-p%C3%BArpura-zapatosq">nike air max zero mujeres rosado p煤rpura</a> <a href="http://www.bewustvitaal.com/kvinders-asics-gel-noosa-tri-10-lyser%C3%B8d-hvid-skoj">kvinders asics gel noosa tri 10 lyser酶d hvid</a> <a href="http://www.flushandhunt.com/nike-kobe-6-gr%C3%A5-gr%C3%B8nn-obuvi">nike kobe 6 gr氓 gr酶nn</a> <a href="http://www.kendalfewster.com/adidas-superstar-blanco-gris-zapatosk">adidas superstar blanco gris</a> <a href="http://www.gisusalon.com/air-yeezy-ii-2-sp-max-90-kvinders-s%C3%B8lv-bl%C3%A5-skoq">air yeezy ii 2 sp max 90 kvinders s酶lv bl氓</a>
    snifferwalk http://www.snifferwalk.com/

  4. <a href="http://www.glasshalfgeek.com/air-jordan-10-retro-blanco-varsity-rojo-negro-ops-3-schuheg">air jordan 10 retro blanco varsity rojo negro ops 3</a> <a href="http://www.kennyrager.com/nike-free-run-2-mujeres-plata-p%C3%BArpura-scarpeg">nike free run 2 mujeres plata p煤rpura</a> <a href="http://www.kevise.com/adidas-climacool-ride-ii-rosado-kurpese">adidas climacool ride ii rosado</a> <a href="http://www.manskapsboden.com/nike-kobe-9-masterpiece-for-salg-today-schuheg">nike kobe 9 masterpiece for salg today</a> <a href="http://www.ogstuff.com/nike-free-flyknit-5.0-rosa-nails-schuheb">nike free flyknit 5.0 rosa nails</a> <a href="http://www.pistaclic.com/nike-roshe-run-hyperfuse-hvid-sort-guld-chaussurese">nike roshe run hyperfuse hvid sort guld</a>
    maxfornet http://www.maxfornet.com/

  5. <a href="http://www.snifferwalk.com/kvinners-asics-gel-kinsei-4-r%C3%B8d-bl%C3%A5-obuvi">kvinners asics gel kinsei 4 r酶d bl氓</a> <a href="http://www.fishmackerel.com/nike-kobe-6-nero-bianca-scarpej">nike kobe 6 nero bianca</a> <a href="http://www.lauraenergy.com/nike-kd-8-grey-pink-shoesh">nike kd 8 grey pink</a> <a href="http://www.magellantt.com/air-jordan-retro-11-mujeres-amarillo-naranja-zapatosp">air jordan retro 11 mujeres amarillo naranja</a> <a href="http://www.sportablecrew.com/nike-air-force-1-rojo-p%C3%BArpura-zapatosk">nike air force 1 rojo p煤rpura</a> <a href="http://www.digisolnc.com/the-north-face-mountain-jacket-1990-northfaceh">the north face mountain jacket 1990</a>
    actconfident http://www.actconfident.com/

  6. <a href="http://www.royalhoneywax.com/michael-kors-bedford-belted-handbag-mkr">michael kors bedford belted handbag</a> <a href="http://www.carslambert.com/barato-new-balance-890-mujeres-naranja-sneakere">barato new balance 890 mujeres naranja</a> <a href="http://www.hiussalipiilo.com/game-ryan-kerrigan-washington-redskins-youth-road-jersey-91-white-nflb">game ryan kerrigan washington redskins youth road jersey 91 white</a> <a href="http://www.hospicevna.com/adidas-zx-630-herre-hvid-shoesc">adidas zx 630 herre hvid</a> <a href="http://www.smartpaul.com/billig-nike-free-5.0-v3-kvinners-r%C3%B8d-skog">billig nike free 5.0 v3 kvinners r酶d</a> <a href="http://www.opendekalbinc.com/yeezy-boost-750-for-sale-quad-cities-sportsf">yeezy boost 750 for sale quad cities</a>
    trulsbakken http://www.trulsbakken.com/

  7. <a href="http://www.lagunawoodsre.com/nike-zoom-pegasus-32-gr%C3%B8n-bl%C3%A5-skoi">nike zoom pegasus 32 gr酶n bl氓</a> <a href="http://www.highbacklink.com/nike-free-run-3-femminile-oro-rosso-scarpeq">nike free run 3 femminile oro rosso</a> <a href="http://www.vuurogen.com/womens-gray-pink-nike-shox-shoesj">womens gray pink nike shox</a> <a href="http://www.rsvppersonnel.com/yellow-michael-kors-purse-mkh">yellow michael kors purse</a> <a href="http://www.shonema.com/air-jordan-eclipse-mint-gr%C3%B8nn-svart-obuvi">air jordan eclipse mint gr酶nn svart</a> <a href="http://www.enventsurvey.com/nike-zoom-clear-out-grigio-arancia-scarpej">nike zoom clear out grigio arancia</a>
    alcovozov http://www.alcovozov.com/

  8. <a href="http://www.fencespacer.com/air-jordan-retro-14-hvid-gr%C3%B8n-dot-chaussuresb">air jordan retro 14 hvid gr酶n dot</a> <a href="http://www.garabebbe.com/nike-wmns-air-max-1-vt-qs-arctic-gr%C3%BCn-obuve">nike wmns air max 1 vt qs arctic gr眉n</a> <a href="http://www.amordeblogger.com/salomon-fellraiser-trail-corriendo-zapatos-mujeres-chaussuresa">salomon fellraiser trail corriendo zapatos mujeres</a> <a href="http://www.astrokasa.com/nike-city-sandal-iii-kinder-orange-braun-butya">nike city sandal iii kinder orange braun</a> <a href="http://www.bnlracing.com/kvinders-asics-gel-quantum-360-s%C3%B8lv-sort-scarpef">kvinders asics gel quantum 360 s酶lv sort</a> <a href="http://www.casbloom.com/nike-free-3.0-flash-lime-nero-butyf">nike free 3.0 flash lime nero</a>
    genovideos http://www.genovideos.com/

  9. <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/

  10. 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/

  11. 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/

  12. 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/

  13. 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/

  14. 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/

  15. 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/

  16. 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/

  17. 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/

  18. 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/

  19. 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]

  20. 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