gtk编程中标签控件设置了gtk_label_set_line_wrap(GTK_LABEL(label),TRUE);为啥也不能自动换行呢?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了gtk编程中标签控件设置了gtk_label_set_line_wrap(GTK_LABEL(label),TRUE);为啥也不能自动换行呢?相关的知识,希望对你有一定的参考价值。
参考技术A 请上传完整的源代码!!参考资料:http://www.92linux.tk
参考技术B 代码不完整无法判断参考资料:http://www.bailangcn.tk/tb.php?sc=ca20db&id=6
swift中标签的页面控制
【中文标题】swift中标签的页面控制【英文标题】:Pagecontrol for label in swift 【发布时间】:2017-05-27 12:27:37 【问题描述】:我有视图控制器,它在带有滚动视图的标签中显示一些文本,但我想为该标签创建一个页面控件,这意味着带有页面控件的标签中的不同文本。我有以下标签代码。
导入基础 导入 UIKit
class tips : UIViewController
@IBOutlet weak var tipsscroll: UIScrollView!
@IBOutlet weak var solutionlabel: UILabel!
override func viewDidLoad()
super.viewDidLoad()
solutionlabel.text = "Some text"
solutionlabel.numberOfLines = 0
solutionlabel.lineBreakMode = NSLineBreakMode.byWordWrapping
// solutionlabel.font = UIFont(name:"HelveticaNeue-Bold", size: 14.0)
提前致谢。
【问题讨论】:
【参考方案1】:为页面控制器和滚动视图创建 IBOutlet
@IBOutlet weak var pageController: UIPageControl!
@IBOutlet weak var ScrollController: UIScrollView!
创建一个数组
let pageString = ["showsHorizontalScrollIndicator working pagecontroller", "running christmas card contact in ", "from the application you can back the Address"]
为滚动视图创建委托方法 UIScrollViewDelegate 和方法
class ViewController: UIViewController, UIScrollViewDelegate
函数和委托方法
// MARK:- Page Controller
func loadScrollView()
let pageCount : CGFloat = CGFloat(pageString.count)
ScrollController.backgroundColor = UIColor.clear
ScrollController.delegate = self
ScrollController.isPagingEnabled = true
ScrollController.contentSize = CGSize(width: ScrollController.frame.size.width * pageCount, height: ScrollController.frame.size.height)
ScrollController.showsHorizontalScrollIndicator = false
ScrollController.alwaysBounceVertical = false
pageController.numberOfPages = Int(pageCount)
pageController.addTarget(self, action: #selector(self.pageChanged), for: .valueChanged)
for i in 0..<Int(pageCount)
print(self.ScrollController.frame.size.width)
let textView = UILabel(frame: CGRect(x: self.ScrollController.frame.size.width * CGFloat(i), y: 0, width: ScreenWidth - 30 , height: 30))
textView.text = pageString[i]
textView.numberOfLines = 0
textView.textColor = UIColor.white
textView.textAlignment = .center
self.ScrollController.addSubview(textView)
//MARK: UIScrollView Delegate
func scrollViewDidScroll(_ scrollView: UIScrollView)
let viewWidth: CGFloat = scrollView.frame.size.width
// content offset - tells by how much the scroll view has scrolled.
let pageNumber = floor((scrollView.contentOffset.x - viewWidth / 50) / viewWidth) + 1
pageController.currentPage = Int(pageNumber)
//MARK: Page tap action
@objc func pageChanged()
let pageNumber = pageController.currentPage
var frame = ScrollController.frame
frame.origin.x = frame.size.width * CGFloat(pageNumber)
frame.origin.y = 0
ScrollController.scrollRectToVisible(frame, animated: true)
最后在 ViewDidload() 中调用函数
loadScrollView()
【讨论】:
以上是关于gtk编程中标签控件设置了gtk_label_set_line_wrap(GTK_LABEL(label),TRUE);为啥也不能自动换行呢?的主要内容,如果未能解决你的问题,请参考以下文章