how can I insert own svg icons into ionic 6? - ionic-framework

Hello how are you? I've been trying to insert my own icons into svg for days, I've seen several blogs but they don't work for me. I'm using ionic version
6.12.2. Does anyone know how I can insert my own svg icons ?

I'm using Sass properties to handle my icons.
In my styles folder, I have a class like _icons-svg.scss, and a class named _mixins.scss
In my _icons-svg.scss :
.icon-svg {
height: 46px;
width: 46px;
background-size: 100% 100% !important;
&.my-first-svg {
#include svg-icon('my-first-svg-icon');
height: 22px;
width: 12px;
}
&.my-second-svg {
#include svg-icon('my-second-svg-icon');
height: 22px;
width: 12px;
}
...
And in my _mixins.scss file, I have :
#mixin svg-icon($icon-name) {
background: url('src/assets/icons/svg/' + $icon-name + '.svg') no-repeat;
}
So replace in the url by the folder containing your svg files.
So my svg file looks like this in my svg folder :
my-first-svg-icon.svg
my-second-svg-icon.svg
And then on my HTML I just have to call like this :
<div class="icon-svg my-second-svg"></div>

Using a SASS mixin was a common way to do this in Ionic 3, but in Ionic 4/5 it's much much simpler. Like you can see in the Ionicons docs:
Custom icons
To use a custom SVG, provide its url in the src attribute to request the external SVG file. The src attribute works the same as in that the url must be accessible from the webpage that's making a request for the image. Additionally, the external file can only be a valid svg and does not allow scripts or events within the svg element.
<ion-icon src="/path/to/external/file.svg"></ion-icon>
So for example you can put your own icons folder in the assets folder, like this:
src
|- app
|- ...
|- assets
|- icons
|- user.svg
|- ...
Which can be used then like this:
<ion-icon src="assets/icons/user.svg"></ion-icon>

Related

visual studio code import custom css and js extension

I'd like to install custom styles in order to have different fonts for classes and attributes in visual studio code.
I installed the Custom CSS and JS Loader extension, and followed the guide but it doesn't seem to work.
Here's what I've tried. I created a file styles.css where I put this code:
.mtk1,
.mtk2,
.mtk8,
.mtk9,
.mtk10,
.mtk12,
.mtk11,
.mtk7,
.mtk3,
.mtk13,
.mtk16 {
margin-left: 1px;
font-family: "Indie Flower";
font-size: 1em;
}
.mtk7,
.mtk4 {
font-family: "Arial";
font-size: 0.7em;
}
/*
For the tab titles.
*/
.monaco-icon-label-description-container .label-name {
font-family: "Indie Flower";
font-size: 1.3em;
}
.tabs-container .monaco-icon-label-description-container .label-name,
.sidebar .monaco-icon-label-description-container .label-name,
.quick-open-row .monaco-icon-label-description-container .label-name {
font-family: -apple-system,BlinkMacSystemFont,Segoe WPC,Segoe UI,HelveticaNeue-Light,Ubuntu,Droid Sans,sans-serif;
font-size: 1em;
}
Then in settings.json I added the following settings:
{
"vscode_custom_css.imports": ["file:///home/mat/vscode_extensions/styles.css"],
"vscode_custom_css.policy": true
}
I took the path by typing inside this directory pwd, so it should be correct path. However, it still doesn't want to apply styles, neither fontFamily nor fontSize.
Does anyone knows where the problem is?
Extension didn't work for me but For what it's worth....while i was messing with this...if you go to the help menu, toggle the Developer Tools....
It will
Check the network tab > you will see there is one css file that vscode loads up.
file:///Applications/Visual%20Studio%20Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.css
I went into this file and directly edited the css directly...
since i already had a css file that i intended to use with this extension...
#import url("file:///Users/adrian/.vscode/vs-code-styles.css");
Reload & Problem solved.
For example, i love my font but all i wanted was the tag to by with a different font-family then the attributes. After some trial and error, this did it. Mileage may very depending on whether or not vscode is changing these classes all the time.
span:not(.mtk1) + .mtki, span:not(.mtk1) + .mtk6{
font-family: 'Courier New' !important;
}
You have to run VSCode as Administrator and then Enable CSS in JS.
Example path to VSCode located in Applications:
sudo /Applications/Visual\ Studio\ Code.app/Contents/MacOS/Electron
And don't forget to install all those custom fonts to your Mac device.

How to use global or shared styles between components in ionic 4?

In ionic 3 we use app.scss file to write global styles. Ionic 4 is not providing a scss variable to override ion-inputs background as well as many other css properties.
I need to apply a white background to all the ion-inputs. For now, I was able to do it by replicating the following scss code on each component:
:host {
ion-input {
--background: white;
}
}
But I would like to write this code in only one place.
What is the scss file to do it? Do I have to import that file in some place?
You just need to put your css in variable.scss like this
ion-input {
background-color: white;
}
then whenever you are using ion-input it takes background color white.
You can add the custom styles in styles.scss, but remind that if they are intermediate stylesheets, you must add !important to ensure:
ion-input {
--background: var(--ion-color-light) !important;
}
Note: Use var(--ion-color-light) to apply Ionic native light (white) color from variables.scss.

Ionic 3 background colors

Is there a built-in way to set background color on <ion-content> in Ionic 3?
In Ionic 1, we could set the color scheme for <ion-content> using classes like content-stable. In newer versions of Ionic, you can set the color of certain components with input variables, for example <ion-navbar color="dark"> or <ion-item color="dark">.
I've tried this kind of input on ion-content but without any success. I could set background-color manually, for example style="background-color:#ddd;", but if there is a 'proper' way to do this in Ionic I would rather do that instead. What is the 'official' way to do this?
There is no official way of doing this. Ionic does not provide any attribute or API to change the background color of ion-content directly.
You will have to go through setting up the css yourself.
Just eg:
In your scss file :
.bg-style {
background: red;
}
and apply style to content as in your component Html file :
<ion-content class="bg-style">
In your app.scss add:
.content {
background: #f9f9f9;
}
In .scss file, you can try with:
ion-content { background-color: map-get($colors, dark) !important; }

How to change the background color code block markdown github

I am using below syntax
```yaml
stages:
- build
- test
- deploy
```
This helps me to get proper text color and getting box but how to change the background color of the box.
TL;DR: GitHub overrides any styling you apply to your document when it renders it using its own flavor.
However, for other places you can do this with HTML and CSS if you wrap it in a <div> ... </div> pair:
# Code
## Vanilla
``python
print("hello world!")
``
## Flavored V1
<div style="background-color: rgb(50, 50, 50);">
``python
print("Yo!")
``
</div>
I had to remove a backtick ` from each code section in my example in order to render it properly here.
The file above renders as below on VSCode:
You can further change the appearance with CSS, however, I wouldn't recommend it.
P.S: GitHub has global dark themes available under settings.
There is no black them for code blocks in README, But you can workaround and add some custom styles to the <pre> tag or <code> like so:
code[class*="language-"], pre[class*="language-"]
border-radius: 6px
text-shadow: 0 1px #14161800 !important
background: #242424 !important
span.token.operator
background: none
span.token.keyword
color: #866cba
Note: It's a sass way style.

It is posible to load customise HTML view into webView in swift?

suppose I am loading url into webView and it looks like:
But I want to remove some unwanted thing from this url like:
I searched a lot on internet but nothing helpful found.but I think that I have to remove some of tag from HTML view before it's load into webView. but I don't know how to do this.
Is it possible and if yes then how can I perform this action?
Please help me for this.
I have found the solution for my question and for that THIS tutorial helps me a lot.
as shown into this tutorial here is the step by step example for load a customised HTML View into webView.
A Web View From a String:
There are several ways to use a web view. Before attributed strings, this was the only way to get formatted text. The developer would write a string of text in HTML and send it to a UIWebview using the method loadHTMLString. Change the viewDidLoad method to this:
overridefuncviewDidLoad() {
super.viewDidLoad()
letmyHTMLString:String! = "<h1>Hello Pizza!</h1>"
myWebView.loadHTMLString(myHTMLString, baseURL: nil)
}
Line 3 makes a optional string, since the loadHTMString method requires one. Line 4 loads the string, and has a second parameter baseURL, which sets the base URL path for the HTML. Usually we set this to nil but if you had files you wanted to load like images or a style sheet, this would give the default path for the files.
Build and run:
That was pretty boring, so let’s add some more HTML code, replace the string with this, all without a page break.
letmyHTMLString:String! = "<h1 style=\"font-family: Helvetica\">Hello Pizza</h1><p>Tap the buttons above to see <strong>some cool stuff</strong> with <code>UIWebView</code><p><img src=\"https://apppie.files.wordpress.com/2014/09/photo-sep-14-7-40-59-pm_small1.jpg\">"
Youll notice a few places where we used the Quote escape sequence \". WE need to add quotes in a few pplaces and a backslash followed by a quote allows us to do so within a string. Build and Run. That is a little better:
A Web View and CSS From Files:
Trying to make something formatted from a string is not easy. Our work would be easier if we had the HTML in a separate file. Even better would be an external style sheet. Tap Command-N on the keyboard or File>New>File… from the drop-down menu to make a new file. Make a blank file by going to Other under iOS and Empty.
Click next and then name the file myHTML.html. Save the file. In the blank file add the following code:
<!--<DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<!-- Based on lesson from http://www.w3.org/Style/Examples/011/firstcss -->Hello Pizza Home
<!-- Site navigation menu -->
<div class="navbar">
Home
Toppings
Crust
Ovens
</div>
<div class="content">
<!-- Main content -->
<h1>Hello Pizza!</h1>
This is a site for the love of all things pizza!
But we are not just pizza, we are with anything on a flatbread. So look around and you will find naan, flatbreads, pitas and tortilla related stuff too!!!
If that is not enough, check our sister site Hello Pie
<img src="https://apppie.files.wordpress.com/2014/09/photo-sep-14-7-40-59-pm_small1.jpg" alt="" />
<!-- Sign and date the page, it's only polite! -->
</div>
<address>Made 27 October 2012
by makeapppie.com.</address>
Back in the ViewController.swift file change the helloPizza method to this:
#IBAction func helloPizza(sender: UIBarButtonItem) {
let myURL = NSBundle.mainBundle().URLForResource("myHtml", withExtension: "html")
let requestObj = NSURLRequest(URL: myURL!)
myWebView.loadRequest(requestObj)
}
Line 2 creates a url for myHTML.html from what is called the main bundle. The main bundle is the directory we place all of our code files in XCode for a specific project. The main bundle changes location depending on the device. Instead of giving a literal path, we use this relative indicator. Line 3 creates an NSURLRequest, an object we feed into the loadRequest method in line 4. The loadRequest loads the HTML code into the UIWebView. Build and run this. Click the Pizza button and you get this:
This view is not that pretty, but we can add some CSS to clean it up a bit. Create another blank file as you did before, named myCSS.css and add the following to the new file:
body {
color: #eeeeee;
background: #a0a088;
font-family:Helvetica}
h1 {
color: #dd1111;
font-family:Chalkduster;
font-size: 18pt}
a{
font-family:Helvetica;
font-weight: bold;
color: #ffffaa;
text-decoration:none;
padding-left: 5px;
}
img{
padding-left:0;
max-width: 90%;
max-height: 90%;
box-shadow: 3px 3px 3px 0px #202020
}
.navbar {
background-color: #000000;
color: white;
position: absolute;
top: 0em;
left: 0em;
width: 100% }
.content{
padding-left: 1em;
padding-top: 1em;
}
The HTML code in myHTML.Html assumes that the baseURL is the bundle. Build and run and we get a better formatted web view:
Now with this example I can copy the page source from the browser and then I can paste that HTML code into my HTML file and I can make changes like I can remove unwanted tag from that HTML code and later I can load this HTML into webView.