我想在表视图控制器中更改节头的字体类型和字体大小.
我的代码:
func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
let header = view as! UITableViewHeaderFooterView
header.textLabel.textColor = UIColor.blackColor()
header.textLabel.font = UIFont(name: "Futura", size: 38)!
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用.有任何想法吗?
我有一个EditText在开始时被禁用的字段.
我想将其设置为启用,将光标放在其上,键盘应该是可见的.
我尝试了以下代码并且一切正常 - 只有键盘才会显示.
@Override
protected void onCreate(Bundle savedInstanceState{
editText.setEnabled(true);
editText.requestFocus();
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
}
Run Code Online (Sandbox Code Playgroud) 我的应用程序有一个带有图像和文本字段的tableview:
如果我选择一行,两者的颜色将完全变为白色
问题 - 我将图像更改为蓝色图像=渲染为默认值.如果我现在选择一行,我的文本字段的文本颜色将变为白色,但图像将保持蓝色.
我希望图像也将颜色改为白色,但事实并非如此.
我做错了什么?
将图像渲染为模板模式的示例=> default:gray | 自动选择白色
彩色图像的示例呈现为默认模式=>默认值:绿色| 也选择了绿色| 预计白色,但它保持绿色
注意:我正在使用Swift 4 for macOS.
我有一个NSTableView可以填充数据并保存到Core Data中.我想用"设计"显示TableView值.
我已经意识到这样:
效果很好!而这个"解决方案"将自动分页:)
这里有一点我的代码
// Example with statics values
func createHTML() {
let pathToHTMLTemplate = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("basic.html")
let pathToNoticeHTMLTemplate = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("notice.html")
do {
htmlString = try String(contentsOf: pathToInvoiceHTMLTemplate)
for _ in 0 ..< 40 {
var itemHTMLContent = try String(contentsOf: pathToNoticeHTMLTemplate)
itemHTMLContent = itemHTMLContent.replacingOccurrences(of: "#NOTICE_NAME#", with: "My notice")
htmlPositionen += itemHTMLContent
}
htmlString = htmlString.replacingOccurrences(of: "#NOTICE#", with: htmlPositionen)
let totalCount = 20 //Fix value …Run Code Online (Sandbox Code Playgroud) 我想将iOS 9的快速操作添加到我的应用程序中.
我把这段代码放在我的app委托中:
import UIKit
enum ShortcutType: String {
case NewScan = "QuickAction.NewScan"
case Settings = "QuickAction.Settings"
}
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
static let applicationShortcutUserInfoIconKey = "applicationShortcutUserInfoIconKey"
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
UIViewController.prepareInterstitialAds()
if(UIApplication.instancesRespondToSelector(Selector("registerUserNotificationSettings:"))) {
UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil))
}
// QUICK ACTIONS
var launchedFromShortCut = false
if #available(iOS 9.0, *) {
if let shortcutItem = launchOptions?[UIApplicationLaunchOptionsShortcutItemKey] as? UIApplicationShortcutItem {
launchedFromShortCut = true
handleShortCutItem(shortcutItem)
}
} else { …Run Code Online (Sandbox Code Playgroud) 我想更改标签,而选择器视图的值已更改.
问题是我无法通过将选择器视图放到代码中来创建操作.这不可能吗?
使用我的datepicker,我可以这样做:
@IBAction func ChangeDatePicker(sender: AnyObject) {
var dateFormatter = NSDateFormatter()
dateFormatter.dateStyle = NSDateFormatterStyle.MediumStyle
dateFormatter.dateFormat = "HH:mm"
var strDate = dateFormatter.stringFromDate(DatePicker.date)
DateLabel.text = "\(strDate) Uhr"
}
Run Code Online (Sandbox Code Playgroud) (渲染为模板图像)
我试过这段代码:
@IBOutlet weak var imgAdd: NSImageView!
imgAdd.layer?.backgroundColor = CGColor.white
Run Code Online (Sandbox Code Playgroud)
这只会改变背景颜色.
有没有办法以编程方式更改此图像的颜色?
到目前为止,我已经尝试了下面的代码不起作用.(图像颜色不会改变.)
func tintedImage(_ image: NSImage, tint: NSColor) -> NSImage {
guard let tinted = image.copy() as? NSImage else { return image }
tinted.lockFocus()
tint.set()
let imageRect = NSRect(origin: NSZeroPoint, size: image.size)
NSRectFillUsingOperation(imageRect, .sourceAtop)
tinted.unlockFocus()
return tinted
}
imgDok.image = tintedImage(NSImage(named: "myImage")!, tint: NSColor.red)
Run Code Online (Sandbox Code Playgroud) 一起早上好,
示例:在单元格一中,我的右侧有一个红色文本标签.从它左边我包括一个像灰线的图像.
使用此代码,我可以设置一个完整的绿色边框:
cell.Label.layer.borderWidth = 0.5
cell.Label.layer.borderColor = UIColor.greenColor().CGColor
Run Code Online (Sandbox Code Playgroud)
我可以在此文本标签的左侧仅设置边框吗?我使用swift ios8 - 所以,我需要一个快速的解决方案
我问过几次这个任务,但我没有解决方案:(我的问题是,我有一个带有标签活动的Android应用程序,我必须设置我的标签的字体大小,但我不知道怎么样.
在我的活动中,我以编程方式设置我的标签:
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText("MY TAB 1"));
tabLayout.addTab(tabLayout.newTab().setText("MY TAB 2"));
tabLayout.addTab(tabLayout.newTab().setText("MY TAB 3"));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
Run Code Online (Sandbox Code Playgroud)
问题是,最后的1 - 2个字母将被剪切,所以我必须设置较小的字体大小,但如何?
我希望有人能帮助我.