答案 0 :(得分:0)
尝试 imageView.contentMode = .scaleAspectFit 要么 imageView.contentMode = .center
您也可以通过故事板进行此操作。
答案 1 :(得分:0)
您最好的方法是确保包含图片的imageView与您所包围的图片完全成比例,这样任何边缘都没有间隙。然后,imageView的layer.borderColor和layer.borderWidth属性运行良好。
以下是一个示例代码:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event){
switch(keyCode){
case ACTIVE_BUTTON:
//your action here
return true;
}
}
答案 2 :(得分:0)
这是我最新的代码。
func addEdgeAction(image: UIImage) -> UIImage{
let imageView: UIImageView = UIImageView(image: image)
let bgview: UIView = UIView()
bgview.frame = CGRect(x: 0, y: 0, width: imageView.frame.size.width + 200, height: imageView.frame.size.height + 200)
var layer: CALayer = CALayer()
layer = bgview.layer
layer.masksToBounds = true
layer.cornerRadius = CGFloat(8)
layer.borderColor = UIColor.clear.cgColor
layer.borderWidth = 100
let imageView1: UIImageView = UIImageView(image: image)
imageView1.frame = CGRect(x: 100, y: 100, width: imageView.frame.size.width, height: imageView.frame.size.height)
bgview.addSubview(imageView1)
UIGraphicsBeginImageContext(bgview.layer.bounds.size)
layer.render(in: UIGraphicsGetCurrentContext()!)
let roundedImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
//secImg.image = roundedImage
return roundedImage!
}