- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试向屏幕添加一个按钮并以编程方式对其进行编辑,但大多数编辑都没有响应。
这是按钮代码:
@IBOutlet weak var buttonTest: UIButton!
let screen = UIScreen.mainScreen().bounds
let buttonImg = ResizeImage(UIImage(named: "Blokker")!, targetSize: CGSize(width: 50, height: 50))
buttonTest.frame = CGRect(x: 0, y: screen.height - 300, width: screen.width * 0.5, height: screen.width * 0.5)
buttonTest.setImage(buttonImg, forState: .Normal)
buttonTest.setTitle("Test", forState: .Normal)
buttonTest.imageView?.contentMode = .ScaleAspectFit
view.addSubview(buttonTest)
ResizeImage 函数有效,我已经在其他 View Controller 中使用了它。下面引用了该代码。 ButtonTest.frame 方法不起作用,按钮将始终保持在同一位置,而无需编辑大小。图像也无法加载,在图像应该所在的位置,我只能看到一个蓝色方 block 。
有谁知道这个问题怎么解决吗?提前致谢!
调整图像大小函数:
func ResizeImage(image: UIImage, targetSize: CGSize) -> UIImage {
let size = image.size
let widthRatio = targetSize.width / image.size.width
let heightRatio = targetSize.height / image.size.height
// Figure out what our orientation is, and use that to form the rectangle
var newSize: CGSize
if(widthRatio > heightRatio) {
newSize = CGSizeMake(size.width * heightRatio, size.height * heightRatio)
} else {
newSize = CGSizeMake(size.width * widthRatio, size.height * widthRatio)
}
// This is the rect that we've calculated out and this is what is actually used below
let rect = CGRectMake(0, 0, newSize.width, newSize.height)
// Actually do the resizing to the rect using the ImageContext stuff
UIGraphicsBeginImageContextWithOptions(newSize, false, 1.0)
image.drawInRect(rect)
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage
}
最佳答案
我已经在评论中回答了您问题的第一部分
如果您希望图像与源相同,请使用imageView.imageRenderingMode = .AlwaysOriginal
和 imageView.imageRenderingMode = .AlwaysTemplate
如果您希望图像与其容器具有相同的颜色(没有 Alpha channel 的图像将是彩色方 block )
对于框架问题,为什么是下面这行?删除它。
view.addSubview(buttonTest)
Buttontest 已经有一个 super View ,因为它是来自 Storyboard/xib 的导出。另外,如果您使用 Storyboard /xib 设计按钮,请不要更改框架矩形。您应该学习如何为此使用约束。
关于ios - 按钮中的图像无法加载,我只得到一个蓝色方 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37854089/
我有一个 datagridview,它的唯一目的是显示来自数据库的信息。出于某种原因,我还添加了额外的列,每一行都有“查看”链接。所以基本上 datagridView 的目的只是让用户单击“查看”链接
当按下我的按钮时,我不希望它的外观发生变化。当我触摸它时它会变成蓝色。我尝试进入 IB 并取消选中“突出显示调整图像”,但这似乎没有改变任何东西。我还没有选中“显示高亮显示触摸”。我如何禁用此功能?感
我是 CSS 和一般编程的新手,所以如果这是一个初学者问题,我很抱歉,但我自己找不到合适的解决方案。 如果我有特定的颜色代码(十六进制),例如#028dca,我怎样才能得到匹配的颜色? 我在网上找到了
Fiddler中这个图标是什么意思: 它未在 help 中列出. 最佳答案 此图标用于回复 Content-Type=Content-Type: text/html; 关于fiddler - 蓝色<>
默认的 UIButton 圆角矩形是深蓝色的。我希望表格中单元格的文本与这种蓝色相匹配。 我正在使用此代码,但我能找到的唯一蓝色是亮蓝色... cell.textLabel.textColor = [
我试过这个: myButton.highlight(true) 但这只会使按钮变成深蓝色,这就是按钮的“按下”状态。 此外,当我按键盘上的 Enter 键时,该按钮将不起作用。 当我按下回车键时,如何
我有一个 iOS 6 应用程序,它使用以下方法将所有导航栏按钮的色调颜色设置为绿色: [[UIBarButtonItem appearance] setTintColor:[UIColor color
当我创建一个 TreeView 控件时,插入几个项目,然后我使用 TVM_SELECTITEM 选择一个默认项目。但是这个项目没有用蓝色突出显示。稍后,如果我使用鼠标或键盘选择一个项目,它将突出显示。
目前我有代码: import random from psychopy import visual, event win = visual.Window() # A TextStim and five
如何更改 UISwitch 的默认颜色(蓝色)? 最佳答案 我想你要找的是这样的东西 UISwitch *testSwitch; //just something I made up [testSwi
我有一个 MKMap 和一系列 MKAnnotations,所有这些都是红色的,这很好。我在 IB 中选择了“显示用户位置”并将 MKAnnotation 从红色更改为蓝色,我的 viewForAnn
我正在尝试使用 C++ 和 openCV 检测下图中的 3 个蓝色圆圈。 我用这个代码 int main(){ Mat original=imread("img.jpg"); Ma
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: C# Textbox string separation 我想将字符串值即 (red,blue,black)
我正在使用 cocos2d 库制作 iOS 游戏。 假设您有两个具有两种不同颜色的对象 - 在 RGB 中定义为 Blue: 0,0,255 Yellow: 255,255,0 我想添加蓝色和
有没有办法轻松地将给定的十六进制颜色代码分配给更一般的类别(红色、绿色、蓝色、黄色、橙色、粉色、黑色、白色、灰色……)? 比如 #ffcc55 -> 橙色,#f0f0f0 -> 白色,... 编辑:甚
我创建了一个 UIButton: testNavigationButton.setTitle("Test", forState: .Normal) testNavigationButton.layer
我正在尝试编写一个裸机程序来闪烁绿色 LED。事实上,我无法打开或关闭任何 LED。这是一个现成的板。主板名称为 NUCLEO F429ZI。 Board Image 我已经浏览了原理图,并且确信引脚
我们已经使用对话流创建了一个聊天机器人。现在,我们想要对其进行测试,并需要一些测量或分析数据以确保该机器人已准备好向公众开放。我们使用对话框流中的“分析”功能的方法之一。但是,他们的文档中没有包含任何
我可以在设置 Pane 中更改我的应用程序(任何地方)的tintColor。当我更改tintColor,然后尝试返回到默认色调颜色时,导航栏中的某些按钮不会返回蓝色,我该如何处理这个问题? 验证:-
我希望使用非常明亮的金属色或荧光色来指定我的文本和 div 颜色。我还没有找到显示这些的任何标准。这些是否存在于颜色规范中,或者您能否向我推荐任何接近的尝试。谢谢。 最佳答案 Here's一个很好的荧
我是一名优秀的程序员,十分优秀!