SwiftUI - TextEditor with multiple columns - ios

Goal: TextEditor with multiple columns. like on Apple Pages App.
Ex, when you set to 2 or 3 columns, the text is properly distributed:
Using vStacks here is not an option, as we would have multiple blocks of text, when the idea is to have one block that is dynamically distributed into columns.
Tried:
Using TextEditor, but there is no modifier to set columns
import SwiftUI
struct ContentViewView: View {
#State private var fullText: String = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor reprehenderit voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt culpa qui officia deserunt mollit anim est laborum."
var body: some View {
TextEditor(text: $fullText)
.foregroundColor(Color.gray)
.font(.custom("HelveticaNeue", size: 13))
}
}
Using Grid, but obviously all the text keeps on the first column.
import SwiftUI
struct IllustrationsView: View {
let inputText = "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"
let columns = [
GridItem(.adaptive(minimum: 80)),
GridItem(.adaptive(minimum: 80)),
GridItem(.adaptive(minimum: 80)),
GridItem(.adaptive(minimum: 80))
]
var body: some View {
ScrollView {
LazyVGrid(columns: columns, spacing: 20) {
Text(inputText)
}
.padding(.horizontal)
}
.frame(maxHeight: 300)
}
}
Question: How can we have a text that dynamically adjusts according to columns?

Related

Kivy/MD - why is my MDLabel in Scrollview showing the last line when it initially displays (w/image and code)?

I have a Scrollview with an MDLabel in it. When I invoke this MDDialog the MDLabel displays but it display the last page of text on screen initially. I want it to display the first page of text and then let me scroll down.
In this example, if I click and drag my mouse, I can scroll up, but my mousewheel will not scroll up as it does on other Scrollviews I have.
How do I display the first page of text in MDLabel intially?
What my scrollview and MDLabel look like - click here for image
Py - complete run-able minimal code:
from kivymd.app import MDApp
from kivy.lang import Builder
kv = """
MDBoxLayout:
orientation: "vertical"
size_hint_y: None
height: "400dp"
markup: True
ScrollView:
do_scroll_x: False
do_scroll_y: True
size_hint: None, None
size: "500dp", "700dp"
pos_hint: {"center_x": .5, "center_y": 1}
MDLabel:
id: MLogfileText
size_hint: 1,None
text: "Log file"
halign: "left"
text_color: self.theme_cls.primary_light
"""
class ColorLabelApp(MDApp):
def build(self):
screen = Builder.load_string(kv)
screen.ids.MLogfileText.text = (" (first line) Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. (last line)")
return screen
ColorLabelApp().run()
Bind the label's height to its texture_size[1] (i.e. height) as,
MDLabel:
padding: [20, 20]
id: MLogfileText
size_hint: 1,None
height: self.texture_size[1]

How can I insert BLANK lines between lists in BitBucket Markdown?

BitBucket Markdown has a simplified features set to avoid HTML insertion etc. Whatever the reasons are, I can not find a way to insert blank lines between lists.
Please do not redirect me to How to write one new line in Bitbucket markdown?, because this is NOT the same case, that case is about breaking the line and not inserting a blank line.
With the following text:
# This is the problem:
* Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium
* Lorem ipsum dolor sit amet
* consectetur adipiscing elit
* sed do eiusmod tempor incididunt
* At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum
* Lorem ipsum dolor sit amet
* consectetur adipiscing elit
* sed do eiusmod tempor incididunt
* Ut enim ad minima veniam, quis nostrum exercitationem
* Lorem ipsum dolor sit amet
* consectetur adipiscing elit
* sed do eiusmod tempor incididunt
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
I obtain this output:
The problem is the lack of enough space in the transition from inner bullet paragraphs to outer bullet paragraphs, pointed by red arrows here (blue arrows show correct spacing):
If a BLANK LINE can be inserted, that can be a workaround (more or less), but I can't find a way (I have tried HTML, escape sequences, Unicode break chars etc).
Type two spaces to the end of the last line.
Leave a blank line between the two lists.
Insert a zero-width Unicode character in the blank line. You can copy a zero-width space from this Wikipedia article.
Example
* Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium
* Lorem ipsum dolor sit amet
* consectetur adipiscing elit
* sed do eiusmod tempor incididunt<space><space>
<zero-width character>
* At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum
* Lorem ipsum dolor sit amet
[...]
Result

Self sizing tableview cells with Async attributedText

I have a table view and cell created in interface builder.
I've configured:
tableView.estimatedRowHeight = 140
tableView.rowHeight = UITableViewAutomaticDimension
It does work when I set up the cell in cellForRowAt right away:
let text = NSAttributedString(string: "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?")
cell.detail.attributedText = text
But how can we move the heavy lifting to a background task so we have a butter smooth scroll?
If I change the previous code to this:
DispatchQueue.global().async {
let text = NSAttributedString(string: "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?")
DispatchQueue.main.async {
cell.detail.attributedText = text
}
}
Then the self-sizing doesn't work anymore. I think I've tried every single method after updating the text, like setNeedsLayout.
Well it turned out that the most efficient way is to calculate/cache the attributed string and when that job done simply reload the cell !

Cannot convert value of type 'UIImage' to expected argument type 'String'

I am lost, is there any alternative?
let swiftCourse = Course(buttonImage: #imageLiteral(resourceName: "cover_developer"),
title: "Become a Developer",
instructor: "Duc Tran",
featureImage: #imageLiteral(resourceName: "developer"),
introductionVideoURL: URL(String: "https://www.youtube.com/watch?v=Inn2K-V3NFI"),
description: "Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda.")
The way your class Course is set up, presumably it is expecting a String.
Change the argument in the constructor to simply "cover_developer".
Replace your code and try:
let swiftCourse = Course(buttonImage:"cover_developer",
title: "Become a Developer",
instructor: "Duc Tran",
featureImage: "developer",
introductionVideoURL: URL(String: "https://www.youtube.com/watch?v=Inn2K-V3NFI"),
description: "Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda.")

Issues with CSS position: fixed in iOS 9 iPhone 6+ in landscape mode

I found a weird issue with my fixed header under the following conditions:
iphone 6+, landscape mode
safari, at least two tabs opened
my page has a position: fixed header and a body and html with position: relative, height: 100%
After page loads and when scrolling down, all works good, the header is in place and web inspector shows it correctly:
But when you scroll up and pull the page down the screen and release, the header is still visible on the page, but actually it is shifted somewhere below the viewport (see that web inspector does not highlight it).
This fact results in all header elements being unaccessible: you cannot open the menu, click on the logo, or contact button.
The header goes back to normal when:
you scroll down (but breaks again when you scroll back up)
switch to another tab and back
or close other tabs
I tried changing DOM or/and CSS of the header and body, but nothing puts the header back to normal state.
Any thoughts on how it can be fixed?
I am sorry to be the messenger of bad news, but I have no idea what your actual problem is since you posted no actual code. However, I would guess that since your problem is position:fixed, the best way to fix it is by stopping using position:fixed as it seems to not be working for you. Here is how you can equally-smoothly emulate it using only absolute and relative positioning:
<html id="eHTML">
<style>
#eHTML { position: static }
#eBODY { position: relative; overflow:hidden }
#eHTML, #eBODY, #main { width: 100%; height: 100%; margin: 0; top: 0 }
#eBODY>div { position:absolute; left:0;bottom:0 }
#footer {height: 20%;background-color:#88f;width:calc(100% - 14px)/*to account in for 14px scrollbar*/;overflow:hidden}
#main {background-color:#ff8;width:100%;height:100%;overflow:auto}
</style>
<body id=eBODY>
<div id=main>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
<p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
<p>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium,</p>
<p>totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p>
<p>Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.</p>
<p>Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit,</p>
<p>sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.</p>
<p>Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur?</p>
<p>Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur,</p>
<p>vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p>
<br /><br /><br /><br />
</div>
<div id="footer">
Some Random Fixed<br />
Content! Yay, it workz!
</div>
</body>
</html>

Resources