ImageView * imageView = ImageView::create("cocosui/ccicon.png");//新建图片 imageView->setScale9Enabled(true); //是否启用九宫格显示模式 imageViewChild->setSizeType(Widget::SizeType::PERCENT);//设置大小类型
imageViewChild->setSizePercent(Vec2::ANCHOR_MIDDLE);//设置大小比例
imageViewChild->setPositionType(Widget::PositionType::PERCENT);//设置位置类型
imageViewChild->setPositionPercent(Vec2::ANCHOR_MIDDLE);//设置位置比例
imageViewChild->setPosition(Vec2(widgetSize.width / 2.0f,
widgetSize.height / 2.0f));//设置位置
imageView->addTouchEventListener([=](Ref * sender, Widget::TouchEventType type){ if (type == Widget::TouchEventType::ENDED){ float width = CCRANDOM_0_1() * 200 + 50; float height = CCRANDOM_0_1() * 80 + 30; imageVIew->setContentSize(Size(width, height)); imageViewChild->setPositionPercent(Vec2(CCRANDOM_0_1(), CCRANDOM_0_1()); } }); imageVIew->setColor(Color3B(159, 168, 187); //设置图片颜色 imageVIew->setContentSize(Size(250, 115)); //设置图片大小 imageView->setFilppedX(true); //在X轴上翻转 imageView->setScale(0.5); //设置图片放大系数,当前系数+1 imageView->ignoreContentAdaptWithSize(false); //如果设置为true,忽略内容适应,使用系统默认的渲染大小,与实际的图片资源大小无关