diff --git a/cocos/ui/UIImageView.cpp b/cocos/ui/UIImageView.cpp index 42d2dea746..a2461c4aa0 100644 --- a/cocos/ui/UIImageView.cpp +++ b/cocos/ui/UIImageView.cpp @@ -112,7 +112,7 @@ bool ImageView::init(const std::string &imageFileName, TextureResType texType) void ImageView::initRenderer() { _imageRenderer = Scale9Sprite::create(); - _imageRenderer->setScale9Enabled(false); + _imageRenderer->setRenderingType(Scale9Sprite::RenderingType::SIMPLE); addProtectedChild(_imageRenderer, IMAGE_RENDERER_Z, -1); } @@ -185,7 +185,11 @@ void ImageView::setScale9Enabled(bool able) _scale9Enabled = able; - _imageRenderer->setScale9Enabled(_scale9Enabled); + if (_scale9Enabled) { + _imageRenderer->setRenderingType(Scale9Sprite::RenderingType::SLICE); + }else{ + _imageRenderer->setRenderingType(Scale9Sprite::RenderingType::SIMPLE); + } if (_scale9Enabled) { @@ -257,34 +261,8 @@ Node* ImageView::getVirtualRenderer() void ImageView::imageTextureScaleChangedWithSize() { - if (_ignoreSize) - { - if (!_scale9Enabled) - { - _imageRenderer->setScale(1.0f); - } - } - else - { - if (_scale9Enabled) - { - _imageRenderer->setPreferredSize(_contentSize); - _imageRenderer->setScale(1.0f); - } - else - { - Size textureSize = _imageTextureSize; - if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) - { - _imageRenderer->setScale(1.0f); - return; - } - float scaleX = _contentSize.width / textureSize.width; - float scaleY = _contentSize.height / textureSize.height; - _imageRenderer->setScaleX(scaleX); - _imageRenderer->setScaleY(scaleY); - } - } + _imageRenderer->setPreferredSize(_contentSize); + _imageRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); }