本文整理汇总了C++中CAButton::setImageForState方法的典型用法代码示例。如果您正苦于以下问题:C++ CAButton::setImageForState方法的具体用法?C++ CAButton::setImageForState怎么用?C++ CAButton::setImageForState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CAButton
的用法示例。
在下文中一共展示了CAButton::setImageForState方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: showLeftButton
void CANavigationBar::showLeftButton()
{
std::vector<CAButton*>::iterator itr;
for (itr = m_pLeftButtons.begin(); itr != m_pLeftButtons.end(); itr++)
{
(*itr)->removeFromSuperview();
}
m_pLeftButtons.clear();
const CAVector<CAObject*>& buttonItems = m_pItem->getLeftButtonItems();
CCRect rect;
rect.size.width = _px(80);
rect.size.height = this->getBounds().size.height * 0.8f;
rect.origin.x = rect.size.width * 0.7f;
rect.origin.y = this->getBounds().size.height * 0.5f;
for (size_t i=0; i<buttonItems.size(); i++)
{
CABarButtonItem* item = dynamic_cast<CABarButtonItem*>(buttonItems.at(i));
rect.size.width = item ? item->getItemWidth() : _px(80);
rect.origin.x += i * rect.size.width;
CAButton* button = CAButton::createWithCenter(rect, CAButtonTypeCustom);
this->addSubview(button);
if (item == NULL && m_pItem)
{
button->setImageForState(CAControlStateNormal, CAImage::create("source_material/btn_left_white.png"));
button->setImageColorForState(CAControlStateHighlighted, ccc4(255, 255, 200, 255));
button->addTarget(this, CAControl_selector(CANavigationBar::goBack), CAControlEventTouchUpInSide);
}
else if (item)
{
if (item->getImage())
{
button->setImageForState(CAControlStateNormal, item->getImage());
if (item->getHighlightedImage())
{
button->setImageForState(CAControlStateHighlighted, item->getHighlightedImage());
}
else
{
button->setImageColorForState(CAControlStateHighlighted, ccc4(127, 127, 127, 255));
}
}
else
{
button->setTitleForState(CAControlStateNormal, item->getTitle());
button->setTitleColorForState(CAControlStateNormal, m_cButtonColor);
button->setTitleForState(CAControlStateHighlighted, item->getTitle());
button->setTitleColorForState(CAControlStateHighlighted, ccc4(m_cButtonColor.r/2, m_cButtonColor.g/2, m_cButtonColor.b/2, 255));
}
button->addTarget(item->getTarget(), item->getSel(), CAControlEventTouchUpInSide);
}
m_pLeftButtons.push_back(button);
}
}
示例2: buttonBackground
void ButtonTest::buttonBackground()
{
CALabel* buttonImage = CALabel::createWithCenter(CCRect(size.width*0.5, size.height*0.3, size.width*0.4, 50));
buttonImage->setText("ButtonImage");
buttonImage->setFontSize(30 * CROSSAPP_ADPTATION_RATIO);
buttonImage->setTextAlignment(CATextAlignmentCenter);
buttonImage->setColor(ccc4(51, 204, 255, 255));
this->getView()->addSubview(buttonImage);
CAButton* defaultBtn = CAButton::create(CAButtonTypeCustom);
defaultBtn->setCenter(CCRect(size.width*0.25 - 50, size.height*0.4, size.width*0.2, size.height*0.05));
defaultBtn->setTitleForState(CAControlStateNormal, "Normal");
defaultBtn->setTitleForState(CAControlStateSelected,"Selected");
defaultBtn->setTitleForState(CAControlStateHighlighted, "Highlighted");
defaultBtn->setBackGroundViewForState(CAControlStateNormal,CAView::createWithColor(CAColor_green));
defaultBtn->setBackGroundViewForState(CAControlStateHighlighted, CAView::createWithColor(CAColor_yellow));
defaultBtn->setTitleColorForState(CAControlStateAll, ccc4(51, 204, 255, 255));
this->getView()->addSubview(defaultBtn);
CALabel* custom = CALabel::createWithCenter(CCRect(size.width*0.25 - 50, size.height*0.4 + 80, size.width*0.2, 50));
custom->setText("(BackgroundView)");
custom->setFontSize(20 * CROSSAPP_ADPTATION_RATIO);
custom->setTextAlignment(CATextAlignmentCenter);
custom->setColor(ccc4(51, 204, 255, 255));
this->getView()->addSubview(custom);
CAButton* squareRectBtn = CAButton::create(CAButtonTypeSquareRect);
squareRectBtn->setCenter(CCRect(size.width*0.5, size.height*0.4, size.width*0.2, size.height*0.05));
squareRectBtn->setImageForState(CAControlStateNormal,CAImage::create("square_nor.png"));
squareRectBtn->setImageForState(CAControlStateHighlighted, CAImage::create("square_sel.png"));
this->getView()->addSubview(squareRectBtn);
CALabel* square = CALabel::createWithCenter(CCRect(size.width*0.5, size.height*0.4 + 80, size.width*0.2, 50));
square->setText("(StateImage)");
square->setFontSize(20 * CROSSAPP_ADPTATION_RATIO);
square->setTextAlignment(CATextAlignmentCenter);
square->setColor(ccc4(51, 204, 255, 255));
this->getView()->addSubview(square);
CAButton* roundedRectBtn = CAButton::create(CAButtonTypeRoundedRect);
roundedRectBtn->setCenter(CCRect(size.width*0.75 + 50, size.height*0.4, size.width*0.2, size.height*0.05));
roundedRectBtn->setControlState(CAControlStateDisabled);
this->getView()->addSubview(roundedRectBtn);
CALabel* rounded = CALabel::createWithCenter(CCRect(size.width*0.75 + 50, size.height*0.4 + 80, size.width*0.2, 50));
rounded->setText("(Disabled)");
rounded->setFontSize(20 * CROSSAPP_ADPTATION_RATIO);
rounded->setTextAlignment(CATextAlignmentCenter);
rounded->setColor(ccc4(51, 204, 255, 255));
this->getView()->addSubview(rounded);
}
示例3: showLeftButton
void CANavigationBar::showLeftButton()
{
std::vector<CAButton*>::iterator itr;
for (itr = m_pLeftButtons.begin(); itr != m_pLeftButtons.end(); itr++)
{
(*itr)->removeFromSuperview();
}
m_pLeftButtons.clear();
CCArray* buttonItems = m_pItems.back()->getLeftButtonItems();
CCRect rect = this->getBounds();
rect.size.width = rect.size.height * 0.9f;
rect.size.height *= 0.8f;
rect.origin.x = rect.size.width * 0.7f;
rect.origin.y = this->getBounds().size.height / 2;
for (int i=0; i<buttonItems->count(); i++)
{
rect.origin.x += i * rect.size.width * 1.1f;
CAButton* button = CAButton::createWithCenter(rect, CAButtonTypeCustom);
this->addSubview(button);
CABarButtonItem* item = dynamic_cast<CABarButtonItem*>(buttonItems->objectAtIndex(i));
if (item == NULL && m_pItems.size() > 1)
{
button->setImageForState(CAControlStateNormal, CAImage::create("source_material/btn_left_white.png"));
button->setImageColorForState(CAControlStateHighlighted, ccc4(255, 255, 200, 255));
button->addTarget(this, CAControl_selector(CANavigationBar::goBack), CAControlEventTouchUpInSide);
}
else if (item)
{
button->setTitleForState(CAControlStateNormal, item->getTitle());
button->setTitleColorForState(CAControlStateNormal, CAColor_white);
button->setTitleForState(CAControlStateHighlighted, item->getTitle());
button->setTitleColorForState(CAControlStateHighlighted, ccc4(255, 255, 200, 255));
button->setImageForState(CAControlStateNormal, item->getImage());
if (item->getHighlightedImage())
{
button->setImageForState(CAControlStateHighlighted, item->getHighlightedImage());
}
else
{
button->setImageColorForState(CAControlStateHighlighted, ccc4(255, 255, 200, 255));
}
button->addTarget(item->getTarget(), item->getSel(), CAControlEventTouchUpInSide);
}
m_pLeftButtons.push_back(button);
}
}
示例4: viewDidLoad
void DMClassifCatalogViewController::viewDidLoad()
{
CADipRect rect = this->getView()->getBounds();
rect.size.height = 96;
m_uiItems = (unsigned int)(rect.size.width / 300);
m_uiItems = MIN(m_uiItems, 5);
m_uiItems = MAX(m_uiItems, 3);
CAView* bar = CAView::createWithFrame(rect, ccc4(87, 154, 244, 255));
this->getView()->insertSubview(bar, 1);
CADipRect titleRect;
titleRect.origin = rect.size/2;
titleRect.size.width = rect.size.width * 0.5f;
titleRect.size.height = rect.size.height;
CALabel* label = CALabel::createWithCenter(titleRect);
label->setNumberOfLine(1);
label->setFontSize(_px(32));
label->setColor(CAColor_white);
label->setTextAlignment(CATextAlignmentCenter);
label->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter);
label->setText(m_sTitle);
bar->addSubview(label);
CCRect btnRect;
btnRect.size.width = rect.size.height * 0.9f;
btnRect.size.height = rect.size.height * 0.8f;
btnRect.origin.x = btnRect.size.width * 0.7f;
btnRect.origin.y = rect.size.height * 0.5f;
CAButton* button = CAButton::createWithCenter(btnRect, CAButtonTypeCustom);
button->setImageForState(CAControlStateNormal, CAImage::create("source_material/btn_left_white.png"));
button->setImageColorForState(CAControlStateHighlighted, CAColor_gray);
bar->addSubview(button);
button->addTarget(this, CAControl_selector(DMIntroductionController::onReturn), CAControlEventTouchUpInSide);
std::map<string, string> key_value;
CommonHttpManager::getInstance()->send_get(get_url(HttpUrlTypeClassifCatalog, "update", m_sID, "", m_vDatas.size()), key_value, this, CommonHttpJson_selector(DMClassifCatalogViewController::onRequestFinished));
{
CCRect loadingRect = this->getView()->getBounds();
loadingRect.origin.y = _px(96);
loadingRect.size.height -= loadingRect.origin.y;
m_pLoading = CAActivityIndicatorView::createWithFrame(loadingRect);
CAImageView* indicator = CAImageView::createWithFrame(CADipRect(0, 0, 50, 50));
indicator->setImage(CAImage::create(loadingIcon));
m_pLoading->setActivityIndicatorView(indicator);
CAView* bg = CAView::createWithFrame(CADipRect(0, 0, 275, 300), CAColor_clear);
CAImageView* bg2 = CAImageView::createWithFrame(CADipRect(0, 0, 275, 100));
bg2->setImage(CAImage::create(loadingBackground));
bg->addSubview(bg2);
m_pLoading->setActivityBackView(bg);
m_pLoading->setLoadingMinTime(0.4f);
m_pLoading->setColor(CAColor_white);
this->getView()->insertSubview(m_pLoading, CAWindowZoderTop);
m_pLoading->setTargetOnCancel(this, callfunc_selector(DMClassifCatalogViewController::initWithCollectionView));
}
}
示例5: replaceItemAtIndex
void CATabBar::replaceItemAtIndex(size_t index, CATabBarItem* item)
{
if (index < m_pItems.size())
{
m_pItems.replace(index, item);
if (!m_pButtons.empty())
{
CAButton* btn = m_pButtons.at(index);
btn->setTitleForState(CAControlStateAll, item->getTitle());
btn->setImageForState(CAControlStateNormal, item->getImage());
CAImage* selectedImage = item->getSelectedImage()
? item->getSelectedImage()
: item->getImage();
btn->setImageForState(CAControlStateHighlighted, selectedImage);
btn->setImageForState(CAControlStateSelected, selectedImage);
CABadgeView* badgeView = m_pBadgeViews.at(index);
badgeView->setBadgeText(item->getBadgeValue());
}
}
}
示例6: showSelectedBackGround
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());
}
}
示例7: setImageAtIndex
bool CASegmentedControl::setImageAtIndex(CAImage *image, int index, CAControlState controlState)
{
if (!this->indexIsValid(index))
{
return false;
}
CAButton *btn = m_segments.at(index);
if (NULL == btn)
{
return false;
}
btn->setImageForState(controlState, image);
return true;
}
示例8: insertSegmentWithImage
bool CASegmentedControl::insertSegmentWithImage(CAImage *image, int index, CAControlState controlState)
{
const int curItemCount = m_segments.size();
if (index < 0)
{
index = 0;
}
else if (index >= curItemCount)
{
index = curItemCount;
}
CAButton *newBtn = this->createDefaultSegment();
if (NULL == newBtn)
{
return false;
}
newBtn->setImageForState(controlState, image);
m_segments.insert(m_segments.begin() + index, newBtn);
this->addSubview(newBtn);
this->layoutSubviews();
return true;
}
示例9: viewDidLoad
void DMChartsController::viewDidLoad()
{
CCRect rect = this->getView()->getBounds();
rect.size.height = _px(96);
CAView* navigaView = CAView::createWithFrame(rect, ccc4(87, 154, 244, 255));
this->getView()->addSubview(navigaView);
CCRect btnRect;
btnRect.size.width = rect.size.height * 0.9f;
btnRect.size.height = rect.size.height * 0.8f;
btnRect.origin.x = btnRect.size.width * 0.7f;
btnRect.origin.y = rect.size.height * 0.5f;
CAButton* button = CAButton::createWithCenter(btnRect, CAButtonTypeCustom);
button->setImageForState(CAControlStateNormal, CAImage::create("source_material/btn_left_white.png"));
button->setImageColorForState(CAControlStateHighlighted, CAColor_gray);
navigaView->addSubview(button);
button->addTarget(this, CAControl_selector(DMChartsController::onReturn), CAControlEventTouchUpInSide);
CASegmentedControl *segmentedControl = CASegmentedControl::createWithFrame(CCRect(0, 0, 10, 10), 3);
segmentedControl->setTitleAtIndex("总", 0, CAControlStateAll);
segmentedControl->setTitleAtIndex("月", 1, CAControlStateAll);
segmentedControl->setTitleAtIndex("周", 2, CAControlStateAll);
for (int i=0; i<3; i++)
{
segmentedControl->setTitleColorAtIndex(ccc4(87, 154, 244, 255), i, CAControlStateSelected);
segmentedControl->setTitleColorAtIndex(CAColor_white, i, CAControlStateHighlighted);
segmentedControl->setTitleColorAtIndex(CAColor_white, i, CAControlStateNormal);
}
segmentedControl->setBackgroundImageAtIndex(CAImage::create(segNormal1), 0, CAControlStateNormal);
segmentedControl->setBackgroundImageAtIndex(CAImage::create(segNormal1), 0, CAControlStateHighlighted);
segmentedControl->setBackgroundImageAtIndex(CAImage::create(segSelected1), 0, CAControlStateSelected);
segmentedControl->setBackgroundImageAtIndex(CAImage::create(segNormal3), 1, CAControlStateNormal);
segmentedControl->setBackgroundImageAtIndex(CAImage::create(segNormal3), 1, CAControlStateHighlighted);
segmentedControl->setBackgroundImageAtIndex(CAImage::create(segSelected3), 1, CAControlStateSelected);
segmentedControl->setBackgroundImageAtIndex(CAImage::create(segNormal2), 2, CAControlStateNormal);
segmentedControl->setBackgroundImageAtIndex(CAImage::create(segNormal2), 2, CAControlStateHighlighted);
segmentedControl->setBackgroundImageAtIndex(CAImage::create(segSelected2), 2, CAControlStateSelected);
segmentedControl->addTarget(this, CAControl_selector(DMChartsController::onSegmented));
segmentedControl->setSelectedAtIndex(0);
float segmentwid = 300;
CCRect segR = CCRect((this->getView()->getFrame().size.width-_px(segmentwid))/2, _px(15), _px(segmentwid), _px(62));
segmentedControl->setFrame(segR);
navigaView->addSubview(segmentedControl);
this->searchTopItems();
{
CCRect loadingRect = this->getView()->getBounds();
loadingRect.origin.y = _px(96);
loadingRect.size.height -= loadingRect.origin.y;
m_pLoading = CAActivityIndicatorView::createWithFrame(loadingRect);
CAImageView* indicator = CAImageView::createWithFrame(CADipRect(0, 0, 50, 50));
indicator->setImage(CAImage::create(loadingIcon));
m_pLoading->setActivityIndicatorView(indicator);
CAView* bg = CAView::createWithFrame(CADipRect(0, 0, 275, 300), CAColor_clear);
CAImageView* bg2 = CAImageView::createWithFrame(CADipRect(0, 0, 275, 100));
bg2->setImage(CAImage::create(loadingBackground));
bg->addSubview(bg2);
m_pLoading->setActivityBackView(bg);
m_pLoading->setLoadingMinTime(0.3f);
m_pLoading->setColor(CAColor_white);
this->getView()->insertSubview(m_pLoading, CAWindowZoderTop);
m_pLoading->setTargetOnCancel(this, callfunc_selector(DMChartsController::initWithTableView));
}
}
示例10: buildCtrlViews
void CAVideoPlayerControlView::buildCtrlViews()
{
m_glView = CAVideoPlayerView::createWithFrame(getFrame());
m_glView->setFrameOrigin(DPointZero);
m_glView->setColor(ccc4(0, 0, 0, 0));
this->insertSubview(m_glView, 1);
// Bottom Panel Back
CAImageView* bottomPanel = NULL;
do {
DRect frame = m_glView->getFrame();
CAImage* image = CAImage::create("source_material/vdo_panel_bottom_bg.png");
float width = m_glView->getFrame().size.width;
float height = image->getContentSize().height;
bottomPanel = CAImageView::createWithFrame(DRect(0, frame.size.height - height, width, height));
bottomPanel->setImage(image);
m_glView->addSubview(bottomPanel);
} while (0);
// Slider
do {
DRect frame = bottomPanel->getFrame();
CAImage* backImage = CAImage::create("source_material/vdo_progress_back.png");
CAImage* barImage = CAImage::create("source_material/vdo_progress_bar.png");
m_playSlider = CASlider::createWithCenter(DRect(frame.size.width / 2, frame.size.height*0.3, frame.size.width * 0.9, barImage->getContentSize().height));
m_playSlider->setMaxTrackTintImage(backImage);
m_playSlider->setThumbTintImage(barImage);
m_playSlider->setTrackHeight(backImage->getContentSize().height);
m_playSlider->addTargetForTouchUpSide(this, CAControl_selector(CAVideoPlayerControlView::onSlideChanged));
m_playSlider->addTarget(this, CAControl_selector(CAVideoPlayerControlView::onSlideTouched));
bottomPanel->addSubview(m_playSlider);
} while (0);
// Play Pause Button
do {
DRect frame = bottomPanel->getFrame();
CAImage* backImage = CAImage::create("source_material/vdo_pause.png");
CAImage* backImage_h = CAImage::create("source_material/vdo_pause_down.png");
frame.origin.y = frame.size.height * 2 / 3;
frame.origin.x = backImage->getContentSize().width;
frame.size.height = backImage->getContentSize().height;
frame.size.width = backImage->getContentSize().width;
m_playButton = CAButton::createWithCenter(frame, CAButtonTypeCustom);
m_playButton->setImageForState(CAControlStateAll, backImage);
m_playButton->setImageForState(CAControlStateHighlighted, backImage_h);
m_playButton->addTarget(this, CAControl_selector(CAVideoPlayerControlView::onButtonPause), CAControlEventTouchUpInSide);
bottomPanel->addSubview(m_playButton);
} while (0);
// play time
do {
DRect frame = m_playButton->getFrame();
DRect newFrame = DRectZero;
m_playTimeLabel = CALabel::createWithFrame(DRectZero);
m_playTimeLabel->setFontSize(32);
m_playTimeLabel->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter);
m_playTimeLabel->setColor(ccc4(255, 255, 255, 255));
newFrame.origin.x = frame.origin.x * 2 + frame.size.width;
newFrame.origin.y = frame.origin.y;
newFrame.size.width = m_playTimeLabel->getFontSize() * 20;
newFrame.size.height = frame.size.height;
m_playTimeLabel->setFrame(newFrame);
m_playTimeLabel->setText("00:00 / 00:00");
bottomPanel->addSubview(m_playTimeLabel);
} while (0);
// Top Panel Back
CAImageView* topPanel = NULL;
do {
CAImage* image = CAImage::create("source_material/vdo_panel_top_bg.png");
topPanel = CAImageView::createWithFrame(DRect(0, 0, m_glView->getFrame().size.width, image->getContentSize().height));
topPanel->setImage(image);
m_glView->addSubview(topPanel);
} while (0);
// Back Button
CAButton* buttonBack = NULL;
do {
DRect frame = topPanel->getFrame();
// CAImage* backImage = CAImage::create("source_material/vdo_btn_back.png");
// CAImage* backImage_h = CAImage::create("source_material/vdo_btn_back_h.png");
CAImage* backImage = CAImage::create("source_material/btn_left_blue.png");
CAImage* backImage_h = CAImage::create("source_material/btn_left_white.png");
frame.origin.y = frame.size.height / 3;
frame.origin.x = frame.origin.y;
frame.size.height = backImage->getContentSize().height;
frame.size.width = backImage->getContentSize().width;
buttonBack = CAButton::createWithCenter(frame, CAButtonTypeCustom);
buttonBack->setImageForState(CAControlStateAll, backImage);
buttonBack->setImageForState(CAControlStateHighlighted, backImage_h);
buttonBack->addTarget(this, CAControl_selector(CAVideoPlayerControlView::onButtonBack), CAControlEventTouchUpInSide);
topPanel->addSubview(buttonBack);
} while (0);
// Title
do {
DRect frame = buttonBack->getFrame();
DRect r = DRectZero;
r.origin.x = buttonBack->getFrame().origin.x * 2 + buttonBack->getFrame().size.width;
r.origin.y = buttonBack->getFrame().origin.y;
//.........这里部分代码省略.........