CAButton* CASegmentedControl::createDefaultSegment() { CCRect elemFrame = CCRectMake(0, 0, m_itemSize.width, m_itemSize.height); CAButton *newBtn = CAButton::createWithFrame(elemFrame, CAButtonTypeCustom); if (newBtn) { CAView* normalBG = this->getDefaultNormalBackgroundView(); CAView* selectedBG = this->getDefaultSelectedBackgroundView(); CAView* highlightedBG = this->getDefaultHighlightedBackgroundView(); newBtn->setBackGroundViewForState(CAControlStateNormal, normalBG); newBtn->setBackGroundViewForState(CAControlStateSelected, selectedBG); newBtn->setBackGroundViewForState(CAControlStateHighlighted, highlightedBG); newBtn->setAllowsSelected(true); newBtn->setTouchEnabled(false); } return newBtn; }
void CATabBar::showSelectedBackGround() { for (size_t i=0; i<m_pButtons.size(); i++) { CAButton* btn = m_pButtons.at(i); btn->setTitleForState(CAControlStateAll, m_pItems.at(i)->getTitle()); btn->setTitleColorForState(CAControlStateAll, m_sTitleColor); btn->setTitleColorForState(CAControlStateHighlighted, m_sSelectedTitleColor); btn->setTitleColorForState(CAControlStateSelected, m_sSelectedTitleColor); btn->setImageForState(CAControlStateNormal, m_pItems.at(i)->getImage()); CAImage* selectedImage = m_pItems.at(i)->getSelectedImage() ? m_pItems.at(i)->getSelectedImage() : m_pItems.at(i)->getImage(); btn->setImageForState(CAControlStateHighlighted, selectedImage); btn->setImageForState(CAControlStateSelected, selectedImage); btn->setBackGroundViewForState(CAControlStateNormal, CAView::createWithColor(CAColor_clear)); if (m_pSelectedBackGroundImage) { btn->setBackGroundViewForState(CAControlStateHighlighted, CAScale9ImageView::createWithImage(m_pSelectedBackGroundImage)); btn->setBackGroundViewForState(CAControlStateSelected, CAScale9ImageView::createWithImage(m_pSelectedBackGroundImage)); } else { btn->setBackGroundViewForState(CAControlStateHighlighted, CAView::createWithColor(m_sSelectedBackGroundColor)); btn->setBackGroundViewForState(CAControlStateSelected, CAView::createWithColor(m_sSelectedBackGroundColor)); } btn->setAllowsSelected(true); CABadgeView* badgeView = m_pBadgeViews.at(i); badgeView->setBadgeText(m_pItems.at(i)->getBadgeValue()); } }
void SessionsViewController::initMsgTableView() { if (m_msg->empty()) { showAlert(); return; } if (m_msgTableView == NULL) { m_listView = CAListView::createWithFrame(DRect(0,(120),m_winSize.width,(60))); m_listView->setListViewDelegate(this); m_listView->setListViewDataSource(this); m_listView->setAllowsSelection(true); m_listView->setAllowsMultipleSelection(false); m_listView->setListViewOrientation(CAListViewOrientationHorizontal); m_listView->setShowsScrollIndicators(false); m_listView->setSeparatorColor(ccc4(0xf6, 0xf6, 0xf6, 0xff)); m_listView->setBackgroundImage(CAImage::create("common/gray_bg.png")); m_listView->setTag(1); //m_listView->setc this->getView()->addSubview(m_listView); m_msgTableView = CATableView::createWithFrame(DRect(0, (180), m_winSize.width, m_winSize.height - (180))); m_msgTableView->setTableViewDataSource(this); m_msgTableView->setTableViewDelegate(this); m_msgTableView->setScrollViewDelegate(this); m_msgTableView->setAllowsSelection(true); m_msgTableView->setSeparatorColor(ccc4(200, 200, 200, 80)); //m_msgTableView->setSeparatorViewHeight((2)); this->getView()->addSubview(m_msgTableView); CAPullToRefreshView *refreshDiscount = CAPullToRefreshView::create(CAPullToRefreshView::CAPullToRefreshTypeHeader); refreshDiscount->setLabelColor(CAColor_black); m_msgTableView->setHeaderRefreshView(refreshDiscount); m_filterView = CAView::createWithFrame(DRect(0, (120), m_winSize.width, (60))); CAScale9ImageView* imageView = CAScale9ImageView::createWithImage(CAImage::create("common/gray_bg.png")); imageView->setFrame(DRect(0, 0, m_winSize.width, (60))); m_filterView->addSubview(imageView); this->getView()->addSubview(m_filterView); m_filterViewVec.push_back(m_filterView); for (int i = 0; i < 2; i++) { int cnt = 0; if (i == 0) { cnt = TrackNum; } else if (i == 1) { cnt = FormatNum; } m_filterBtn[i] = CAButton::createWithFrame(DRect(i * m_winSize.width / 2, 0, m_winSize.width / 2, (60)), CAButtonTypeCustom); m_filterBtn[i]->setTitleForState(CAControlStateAll, filterItem[i]); m_filterBtn[i]->setTitleFontName(SAP_FONT_ARIAL); m_filterBtn[i]->setTitleFontSize((30)); m_filterBtn[i]->setTitleColorForState(CAControlStateAll, CAColor_gray); m_filterBtn[i]->addTarget(this, CAControl_selector(SessionsViewController::buttonCallBack), CAControlEventTouchUpInSide); m_filterBtn[i]->setTag(300 + i); m_filterBtn[i]->setAllowsSelected(true); m_filterView->addSubview(m_filterBtn[i]); m_downView[i] = CAView::createWithFrame(DRect(i * m_winSize.width / 2, (180), m_winSize.width / 2, (50) * cnt + (20))); CAScale9ImageView* imageView = CAScale9ImageView::createWithImage(CAImage::create("common/gray_bg.png")); imageView->setFrame(DRect(0, 0, m_winSize.width / 2, (50) * cnt + (20))); m_downView[i]->addSubview(imageView); this->getView()->addSubview(m_downView[i]); m_filterViewVec.push_back(m_downView[i]); } for (int i = 0; i < m_filterViewVec.size(); i++) { m_filterViewVec[i]->setVisible(false); } for (int i = 0; i < TrackNum; i++) { CAButton* button = CAButton::createWithFrame(DRect((20), (50) * i, m_winSize.width / 2 - (40), (50)), CAButtonTypeCustom); button->setTitleForState(CAControlStateAll, trackFilterItem[i]); button->setTitleFontName(SAP_FONT_ARIAL); button->setTitleColorForState(CAControlStateAll, CAColor_gray); button->setTitleColorForState(CAControlStateSelected, CAColor_white); button->setTitleFontSize((27)); button->setAllowsSelected(true); //CAImageView* imageView = CAImageView::createWithImage(CAImage::create("common/white_bg.png")); //button->setBackgroundViewForState(CAControlStateAll, imageView); CAImageView* imageView = CAImageView::createWithImage(CAImage::create("common/sky_bg.png")); button->setBackgroundViewForState(CAControlStateSelected, imageView); button->addTarget(this, CAControl_selector(SessionsViewController::buttonCallBack), CAControlEventTouchUpInSide); button->setTag(400 + i); m_downView[0]->addSubview(button); m_trackButtonVec.push_back(button); } for (int i = 0; i < FormatNum; i++) { CAButton* button = CAButton::createWithFrame(DRect((20), (50) * i, m_winSize.width / 2 - (40), (50)), CAButtonTypeCustom); button->setTitleForState(CAControlStateAll, formatFilterItem[i]); button->setTitleFontName(SAP_FONT_ARIAL); button->setTitleColorForState(CAControlStateAll, CAColor_gray); button->setTitleColorForState(CAControlStateSelected, CAColor_white); button->setTitleFontSize((27)); button->setAllowsSelected(true); //CAImageView* imageView = CAImageView::createWithImage(CAImage::create("common/white_bg.png")); //button->setBackgroundViewForState(CAControlStateAll, imageView); CAImageView* imageView = CAImageView::createWithImage(CAImage::create("common/sky_bg.png")); button->setBackgroundViewForState(CAControlStateSelected, imageView); button->addTarget(this, CAControl_selector(SessionsViewController::buttonCallBack), CAControlEventTouchUpInSide); button->setTag(500 + i); m_downView[1]->addSubview(button); m_formatButtonVec.push_back(button); } } }
void ButtonTest::buttonBackground(void) { CADipSize size = bkgView->getBounds().size; CALabel* buttonImage = CALabel::createWithCenter(CADipRect(size.width*0.5, size.height*0.2, size.width*0.4, 50)); buttonImage->setText("ButtonImage"); buttonImage->setFontSize(_px(30)); buttonImage->setTextAlignment(CATextAlignmentCenter); buttonImage->setColor(ccc4(51, 204, 255, 255)); bkgView->addSubview(buttonImage); CAButton* defaultBtn = CAButton::create(CAButtonTypeCustom); defaultBtn->setCenter(CADipRect(size.width*0.25 - 50, size.height*0.5, size.width*0.25, size.height*0.1)); defaultBtn->setTitleForState(CAControlStateNormal, "Normal"); defaultBtn->setTitleColorForState(CAControlStateNormal, CAColor_white); defaultBtn->setTitleForState(CAControlStateSelected,"Selected"); defaultBtn->setTitleForState(CAControlStateHighlighted, "Highlighted"); defaultBtn->setBackGroundViewForState(CAControlStateNormal,CAView::createWithColor(CAColor_green)); defaultBtn->setBackGroundViewForState(CAControlStateHighlighted, CAView::createWithColor(CAColor_yellow)); bkgView->addSubview(defaultBtn); CALabel* custom = CALabel::createWithCenter(CADipRect(size.width*0.25 - 50, size.height*0.5 + 80, size.width*0.3, 50)); custom->setText("(BackgroundView)"); custom->setFontSize(_px(20)); custom->setTextAlignment(CATextAlignmentCenter); custom->setColor(CAColor_blueStyle); bkgView->addSubview(custom); CAButton* squareRectBtn = CAButton::create(CAButtonTypeSquareRect); squareRectBtn->setAllowsSelected(true); squareRectBtn->setCenter(CADipRect(size.width*0.5, size.height*0.5, size.width*0.25, size.height*0.1)); squareRectBtn->setTitleForState(CAControlStateNormal, "Normal"); squareRectBtn->setTitleColorForState(CAControlStateNormal, CAColor_white); squareRectBtn->setTitleForState(CAControlStateSelected, "Selected"); squareRectBtn->setTitleForState(CAControlStateHighlighted, "Highlighted"); squareRectBtn->setBackGroundViewForState(CAControlStateNormal, CAScale9ImageView::createWithImage(CAImage::create("source_material/btn_rounded3D_normal.png"))); squareRectBtn->setBackGroundViewForState(CAControlStateHighlighted, CAScale9ImageView::createWithImage(CAImage::create("source_material/ex4.png"))); squareRectBtn->setBackGroundViewForState(CAControlStateSelected, CAScale9ImageView::createWithImage(CAImage::create("source_material/btn_rounded3D_selected.png"))); bkgView->addSubview(squareRectBtn); CALabel* square = CALabel::createWithCenter(CADipRect(size.width*0.5, size.height*0.5 + 80, size.width*0.3, 50)); square->setText("(StateImage)"); square->setFontSize(_px(20)); square->setTextAlignment(CATextAlignmentCenter); square->setColor(CAColor_blueStyle); bkgView->addSubview(square); CAButton* roundedRectBtn = CAButton::create(CAButtonTypeRoundedRect); roundedRectBtn->setCenter(CADipRect(size.width*0.75 + 50, size.height*0.5, size.width*0.25, size.height*0.1)); roundedRectBtn->setBackGroundViewForState(CAControlStateDisabled, CAScale9ImageView::createWithImage(CAImage::create("source_material/ex5.png"))); roundedRectBtn->setControlState(CAControlStateDisabled); bkgView->addSubview(roundedRectBtn); CALabel* rounded = CALabel::createWithCenter(CADipRect(size.width*0.75 + 50, size.height*0.5 + 80, size.width*0.3, 50)); rounded->setText("(Disabled)"); rounded->setFontSize(_px(20)); rounded->setTextAlignment(CATextAlignmentCenter); rounded->setColor(CAColor_blueStyle); bkgView->addSubview(rounded); }